Home Mysql Dumps Oracle Mcq's Practise Java Dumps


Page of  
Customer Table Booking - Requirement 1  
Your friend has opened up a new restaurant and he finds it difficult to keep track of the tables  
booked by customers. Being an aspirant programmer help your friend with a small application that  
would help him keep track of the tables booked. There are three major domains Table, Customer,  
and Booking. The Table and Customer domain are used to store table and Customer details  
respectively. The third domain Booking is used maintain the booking details of a Customer  
corresponding to a particular table.  
Requirement 1:  
Let’s start off by creating Customer objects and check whether two objects are equal by overriding  
equals method.  
1. Create a Customer Class with the following private attributes:  
Member Field Name  
id  
Type  
Long  
name  
String  
mobileNumber  
birthdate  
String  
java.util.Date  
Double  
Double  
java.util.Date  
Double  
averageSpendAmount  
totalAmount  
dateEnrolled  
rating  
2
3
4
. Mark all the attributes as private  
. Create / Generate appropriate Getters & Setters  
. Add a default constructor and a parameterized constructor to take in all attributes in the  
given order: Customer(Long id, String name, String mobileNumber, java.util.Date  
birthdate, Double averageSpendAmount, Double totalAmount, java.util.Date dateEnrolled,  
Double rating)  
5. When the “customer” object is printed, it should display the following details: [Override  
the toString method]  
Print format:  
Id:"id"  
Name:"name"  
Mobile Number:"mob num"  
Date of Birth:"dob"  
Average spent amount:"avg spent amount"  
Total amount:"total amount"  
Date Enrolled:"date enrolled"  
Rating:"rating"  
6
. Two customers are considered same if they have the same name, mobileNumber,  
andbirthdate. Implement the logic in the appropriate function. (Case –  
Insensitive) [Override the equals method]  
The return type of Equals method is bool(either true or false), If it returns true, then print  
"
Customer 1 is same as Customer 2", else print "Customer 1 and Customer 2 are  
different", That print statement will be present in the main method.  
7. The input format consists of customer details separated by comma in the below order,  
(
id, name, mobileNumber, birthdate, averageSpendAmount, totalAmount, dateEnrolled,  
rating)  
The Input to your program would be details of two customers, you need to display their details as  
given in "5th point(refer above)" and compare the two customers and display if the Customers are  
same or different.  
Create a class named as Main, which contains the main method, all the input, and output operations  
are performed in this method(main).  
Note: There is an empty line between display statements. The empty lines are displayed in the Main  
method.  
Sample INPUT & OUTPUT 1:  
Enter the details of Customer 1:  
1
,John,9876543210,12-12-1990,5000,25000,12-12-2012,3  
Enter the details of Customer 2:  
,James,9876543201,12-12-1991,6000,35000,12-12-2013,4  
2
Details of customer 1:  
Id:1  
Name:John  
Mobile Number:9876543210  
Date of Birth:12-12-1990  
Average spent amount:5000.0  
Total amount:25000.0  
Date Enrolled:12-12-2012  
Rating:3.0  
Details of customer 2:  
Id:2  
Name:James  
Mobile Number:9876543201  
Date of Birth:12-12-1991  
Average spent amount:6000.0  
Total amount:35000.0  
Date Enrolled:12-12-2013  
Rating:4.0  
Customer 1 and Customer 2 are different  
Sample INPUT & OUTPUT 2:  
Enter the details of Customer 1:  
1
,John,9876543210,12-12-1990,5000,25000,12-12-2012,3  
Enter the details of Customer 2:  
,John,9876543210,12-12-1990,8000,28000,12-11-2012,3.5  
2
Details of customer 1:  
Id:1  
Name:John  
Mobile Number:9876543210  
Date of Birth:12-12-1990  
Average spent amount:5000.0  
Total amount:25000.0  
Date Enrolled:12-12-2012  
Rating:3.0  
Details of customer 2:  
Id:2  
Name:John  
Mobile Number:9876543210  
Date of Birth:12-12-1990  
Average spent amount:8000.0  
Total amount:28000.0  
Date Enrolled:12-11-2012  
Rating:3.5  
Customer 1 is same as Customer 2  
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
public class Main {  
public static void main(String args[]) throws IOException, NumberFormatException, ParseException  
{
//fill the code  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
Customer c[]=new Customer[2];  
for(int i=0;i<2;i++){  
System.out.println("Enter the details of Customer "+(i+1)+":");  
String cd=br.readLine();  
String s[]=cd.split(",");  
c[i]=new  
Customer(Long.parseLong(s[0]),s[1],s[2],sdf.parse(s[3]),Double.parseDouble(s[4]),Double.parseDou  
ble(s[5]),sdf.parse(s[6]),Double.parseDouble(s[7]));  
}
int idd=1;  
for(Customer cus:c)  
{
System.out.println("Details of customer "+(idd)+":");  
System.out.println(cus);  
idd++;  
}
if(c[0].equals(c[1]))  
{
System.out.println("Customer 1 is same as Customer 2");  
}
else  
System.out.println("Customer 1 and Customer 2 are different");  
}
}
import java.text.SimpleDateFormat;  
import java.util.Date;  
public class Customer {  
//fill the code  
private Long id;  
private String name;  
private String mobileNumber;  
private java.util.Date birthdate;  
private Double averageSpendAmount;  
private Double totalAmount;  
private java.util.Date dateEnrolled;  
private Double rating;  
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public String getMobileNumber() {  
return mobileNumber;  
}
public void setMobileNumber(String mobileNumber) {  
this.mobileNumber = mobileNumber;  
}
public java.util.Date getBirthdate() {  
return birthdate;  
}
public void setBirthdate(java.util.Date birthdate) {  
this.birthdate = birthdate;  
}
public Double getAverageSpendAmount() {  
return averageSpendAmount;  
}
public void setAverageSpendAmount(Double averageSpendAmount) {  
this.averageSpendAmount = averageSpendAmount;  
}
public Double getTotalAmount() {  
return totalAmount;  
}
public void setTotalAmount(Double totalAmount) {  
this.totalAmount = totalAmount;  
}
public java.util.Date getDateEnrolled() {  
return dateEnrolled;  
}
public void setDateEnrolled(java.util.Date dateEnrolled) {  
this.dateEnrolled = dateEnrolled;  
}
public Double getRating() {  
return rating;  
}
public void setRating(Double rating) {  
this.rating = rating;  
}
public Customer(Long id, String name, String mobileNumber, Date birthdate,  
Double averageSpendAmount, Double totalAmount, Date dateEnrolled,  
Double rating) {  
super();  
this.name = name;  
this.mobileNumber = mobileNumber;  
this.birthdate = birthdate;  
this.averageSpendAmount = averageSpendAmount;  
this.totalAmount = totalAmount;  
this.dateEnrolled = dateEnrolled;  
this.rating = rating;  
}
public Customer() {  
super();  
}
@
Override  
public int hashCode() {  
final int prime = 31;  
int result = 1;  
result = prime * result  
+
((birthdate == null) ? 0 : birthdate.hashCode());  
result = prime * result  
+
((mobileNumber == null) ? 0 : mobileNumber.hashCode());  
result = prime * result + ((name == null) ? 0 : name.hashCode());  
return result;  
}
@
Override  
public boolean equals(Object obj) {  
if (this == obj)  
return true;  
if (obj == null)  
return false;  
if (getClass() != obj.getClass())  
return false;  
Customer other = (Customer) obj;  
if (birthdate == null) {  
if (other.birthdate != null)  
return false;  
}
else if (!birthdate.equals(other.birthdate))  
return false;  
if (mobileNumber == null) {  
if (other.mobileNumber != null)  
return false;  
}
else if (!mobileNumber.equals(other.mobileNumber))  
return false;  
if (name == null) {  
if (other.name != null)  
return false;  
}
else if (!name.equals(other.name))  
return false;  
return true;  
}
@
Override  
public String toString() {  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
return "Id:"+id+"\nName:"+name+"\nMobile Number:"+mobileNumber+"\nDate of  
Birth:"+sdf.format(birthdate)+"\nAverage spent amount:"+averageSpendAmount+"\nTotal  
amount:"+totalAmount+"\nDate Enrolled:"+sdf.format(dateEnrolled)+"\nRating:"+rating;  
}
}
Page of  
Customer Table Booking - Requirement 2  
Requirement 2:  
One of the main features of any application is searching. In this requirement, you need to  
search customers based on name, birthdate, and rating.  
a) Create a Customer Class with the following private attributes:  
Member Field Name  
id  
Type  
Long  
name  
String  
mobileNumber  
birthdate  
String  
java.util.Date  
Double  
Double  
java.util.Date  
Double  
averageSpendAmount  
totalAmount  
dateEnrolled  
rating  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters,Add a  
default constructor and a parameterized constructor to take in all attributes in the given  
order:Customer(Long id, String name, String mobileNumber, java.util.Date  
birthdate, Double averageSpendAmount, Double totalAmount, java.util.Date  
dateEnrolled, Double rating)  
b) Create the following static methods in theContactBO class,  
Method Name  
Description  
This method accepts a String as argument. Comma-separated  
Customer detail is passed to this method. Split the value then  
create a customer object and return the customer object.  
static Customer createCustomer(String  
line)  
static List<Customer>  
findCustomer(List<Customer>  
customerList,String name)  
This method accepts customer list and a customer name as  
arguments. Find the list of customers with given name and retu  
the list. If no customers found with the given name return null.  
static List<Customer>  
findCustomer(List<Customer>  
customerList,Date birth)  
This method accepts customer list and birth date as arguments  
Find the list of customers with the given birth date and return t  
list. If no customers found with the givenbirth date return null  
This method accepts customer list and rating as argumen  
Find the list of customers with the given rating value and  
return the list. If no customers found with the givenrating retu  
null.  
static List<Customer>  
findCustomer(List<Customer>  
customerList,Double rating)  
The input format consists of customer details separated by comma in the below order,  
id, name, mobileNumber, birthdate, averageSpendAmount, totalAmount, dateEnrolled, rating)  
(
When the “customer” object is printed, it should display the following format  
Print format:  
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n",  
"
Id","Name","Mobile Number","Date of Birth","Average spent amount","Total  
amount","Date Enrolled","Rating");  
Sample INPUT & OUTPUT 1:  
Enter the number of customers:  
3
1,John,9876543210,12-12-1990,5000,25000,12-12-2012,3  
2,James,9876543201,12-12-1991,6000,35000,12-12-2013,4  
3,John,9567843201,14-09-1987,6000,35000,12-12-2013,4  
Enter the search type:  
1
2
3
1
.By name  
.By birth date  
.By rating  
Enter the name of the customer to be searched:  
John  
Id Name  
Mobile Number Date of Birth Average spent amount Total amount Date  
Enrolled Rating  
1
3
John  
John  
9876543210 12-12-1990 5000.0  
9567843201 14-09-1987 6000.0  
25000.0  
35000.0  
12-12-2012 3.0  
12-12-2013 4.0  
Sample INPUT & OUTPUT 2:  
Enter the number of customers:  
3
1,John,9876543210,12-12-1990,5000,25000,12-12-2012,3  
2,James,9876543201,12-12-1991,6000,35000,12-12-2013,4  
3,Parker,9567843201,14-09-1987,6000,35000,12-12-2013,4  
Enter the search type:  
1
2
3
3
.By name  
.By birth date  
.By rating  
Enter the rating of the customer to be searched:  
4
Id Name  
Mobile Number Date of Birth Average spent amount Total amount Date  
Enrolled Rating  
2
3
James  
Parker  
9876543201 12-12-1991 6000.0  
9567843201 14-09-1987 6000.0  
35000.0  
35000.0  
12-12-2013 4.0  
12-12-2013 4.0  
Sample INPUT & OUTPUT 3:  
Enter the number of customers:  
3
1,John,9876543210,12-12-1990,5000,25000,12-12-2012,3  
2,James,9876543201,12-12-1990,6000,35000,12-12-2013,4  
3,Parker,9567843201,14-09-1987,6000,35000,12-12-2013,4  
Enter the search type:  
1
2
3
2
.By name  
.By birth date  
.By rating  
Enter the birth date of the customer to be searched:  
2-12-1990  
1
Id Name  
Mobile Number Date of Birth Average spent amount Total amount Date  
Enrolled Rating  
1
2
John  
James  
9876543210 12-12-1990 5000.0  
9876543201 12-12-1990 6000.0  
25000.0  
35000.0  
12-12-2012 3.0  
12-12-2013 4.0  
Sample INPUT & OUTPUT 4:  
Enter the number of customers:  
3
1,John,9876543210,12-12-1990,5000,25000,12-12-2012,3  
2,James,9876543201,12-12-1991,6000,35000,12-12-2013,4  
3,John,9567843201,14-09-1987,6000,35000,12-12-2013,4  
Enter the search type:  
1
2
3
1
.By name  
.By birth date  
.By rating  
Enter the name of the customer to be searched:  
Starc  
No customers found with the given name  
Sample INPUT & OUTPUT 5:  
Enter the number of customers:  
3
1,John,9876543210,12-12-1990,5000,25000,12-12-2012,3  
2
3
,James,9876543201,12-12-1991,6000,35000,12-12-2013,4  
,Parker,9567843201,14-09-1987,6000,35000,12-12-2013,4  
Enter the search type:  
1
2
3
3
.By name  
.By birth date  
.By rating  
Enter the rating of the customer to be searched:  
.5  
3
No customers found with the given rating  
Sample INPUT & OUTPUT 6:  
Enter the number of customers:  
3
1,John,9876543210,12-12-1990,5000,25000,12-12-2012,3  
2,James,9876543201,12-12-1990,6000,35000,12-12-2013,4  
3,Parker,9567843201,14-09-1987,6000,35000,12-12-2013,4  
Enter the search type:  
1
2
3
2
.By name  
.By birth date  
.By rating  
Enter the birth date of the customer to be searched:  
0-10-1998  
1
No customers found with the given birth date  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
public class CustomerBO {  
public static Customer createCustomer(String line) throws Exception{  
/
/fill the code  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
String a1[]=line.split(",");  
Customer c=new  
Customer(Long.parseLong(a1[0]),a1[1],a1[2],sdf.parse(a1[3]),Double.parseDouble(a1[4]),Doubl  
e.parseDouble(a1[5]),sdf.parse(a1[6]),Double.parseDouble(a1[7]));  
return c;  
}
public static List<Customer> findCustomer(List<Customer> customerList,String name) {  
/
/fill the code  
List<Customer> l1=new ArrayList<>();  
for(Customer c:customerList)  
{
if(c.getName().equals(name))  
{
l1.add(c);  
}
}
if(l1.isEmpty())  
return null;  
else  
return l1;  
}
public static List<Customer> findCustomer(List<Customer> customerList,Date birth) {  
/
/fill the code  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
List<Customer> l2=new ArrayList<>();  
//System.out.println("yi");  
for(Customer c1:customerList)  
{
/
/System.out.println(sdf.format(c1.getBirthdate())+sdf.format(birth));  
if(sdf.format(c1.getBirthdate()).equals(sdf.format(birth)))  
{
// System.out.println(sdf.format(c1.getBirthdate())+sdf.format(birth));  
l2.add(c1);  
}
}
if(l2.isEmpty())  
return null;  
else  
return l2;  
}
public static List<Customer> findCustomer(List<Customer> customerList,Double rating) {  
/
/fill the code  
List<Customer> l3=new ArrayList<>();  
for(Customer c2:customerList)  
{
if(c2.getRating().equals(rating))  
{
l3.add(c2);  
}
}
if(l3.isEmpty())  
return null;  
else  
return l3;  
}
}
import java.util.Date;  
public class Customer {  
//fill the code  
private Long id;  
private String name;  
private String mobileNumber;  
private java.util.Date birthdate;  
private Double averageSpendAmount;  
private Double totalAmount;  
private java.util.Date dateEnrolled;  
private Double rating;  
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public String getMobileNumber() {  
return mobileNumber;  
}
public void setMobileNumber(String mobileNumber) {  
this.mobileNumber = mobileNumber;  
}
public java.util.Date getBirthdate() {  
return birthdate;  
}
public void setBirthdate(java.util.Date birthdate) {  
this.birthdate = birthdate;  
}
public Double getAverageSpendAmount() {  
return averageSpendAmount;  
}
public void setAverageSpendAmount(Double averageSpendAmount) {  
this.averageSpendAmount = averageSpendAmount;  
}
public Double getTotalAmount() {  
return totalAmount;  
}
public void setTotalAmount(Double totalAmount) {  
this.totalAmount = totalAmount;  
}
public java.util.Date getDateEnrolled() {  
return dateEnrolled;  
}
public void setDateEnrolled(java.util.Date dateEnrolled) {  
this.dateEnrolled = dateEnrolled;  
}
public Double getRating() {  
return rating;  
}
public void setRating(Double rating) {  
this.rating = rating;  
}
public Customer(Long id, String name, String mobileNumber, Date birthdate,  
Double averageSpendAmount, Double totalAmount, Date dateEnrolled,  
Double rating) {  
this.name = name;  
this.mobileNumber = mobileNumber;  
this.birthdate = birthdate;  
this.averageSpendAmount = averageSpendAmount;  
this.totalAmount = totalAmount;  
this.dateEnrolled = dateEnrolled;  
this.rating = rating;  
}
public Customer() {  
super();  
}
}
import java.io.BufferedReader;  
import java.io.InputStreamReader;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
public class Main {  
public static void main(String args[]) throws Exception{  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
CustomerBO cb=new CustomerBO();  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
List<Customer> customerList=new ArrayList<>();  
System.out.println("Enter the number of customers:");  
Integer count = Integer.parseInt(br.readLine());  
/
/fill the code  
for(int i=0;i<count;i++)  
{
String line=br.readLine();  
Customer c=CustomerBO.createCustomer(line);  
customerList.add(c);  
}
System.out.println("Enter the search type:\n1.By name\n2.By birth date\n3.By rating");  
Integer choice=Integer.parseInt(br.readLine());  
//fill the code  
switch(choice)  
{
case 1:  
System.out.println("Enter the name of the customer to be searched:");  
String name=br.readLine();  
List<Customer> l1=CustomerBO.findCustomer(customerList, name);  
if(l1==null){  
System.out.println("No customers found with the given name");  
System.exit(0);}  
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n", "Id","Name","Mobile  
Number","Date of Birth","Average spent amount","Total amount","Date Enrolled","Rating");  
for(Customer c:l1)  
{
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n",  
c.getId(),c.getName(),c.getMobileNumber(),sdf.format(c.getBirthdate()),c.getAverageSpendAm  
ount(),c.getTotalAmount(),sdf.format(c.getDateEnrolled()),c.getRating());  
}
break;  
case 2:  
System.out.println("Enter the birth date of the customer to be searched:");  
String birth=br.readLine();  
Date d=sdf.parse(birth);  
List<Customer> l2=CustomerBO.findCustomer(customerList,d);  
if(l2==null){  
System.out.println("No customers found with the given birth date");  
System.exit(0);}  
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n", "Id","Name","Mobile  
Number","Date of Birth","Average spent amount","Total amount","Date Enrolled","Rating");  
for(Customer c1:l2)  
0
0
000000000000000000000000000000000000000000000000000000000000000000000000000  
00000000000000000000000000{  
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n",  
c1.getId(),c1.getName(),c1.getMobileNumber(),sdf.format(c1.getBirthdate()),c1.getAverageSpe  
ndAmount(),c1.getTotalAmount(),sdf.format(c1.getDateEnrolled()),c1.getRating());  
}
break;  
case 3:  
System.out.println("Enter the rating of the customer to be searched:");  
Double rating=Double.parseDouble(br.readLine());  
List<Customer> l3=CustomerBO.findCustomer(customerList, rating);  
if(l3==null){  
System.out.println("No customers found with the given rating ");  
System.exit(0);}  
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n", "Id","Name","Mobile  
Number","Date of Birth","Average spent amount","Total amount","Date Enrolled","Rating");  
for(Customer c2:l3)  
{
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n",  
c2.getId(),c2.getName(),c2.getMobileNumber(),sdf.format(c2.getBirthdate()),c2.getAverageSpe  
ndAmount(),c2.getTotalAmount(),sdf.format(c2.getDateEnrolled()),c2.getRating());  
}
break;  
}
}
}
Page of  
Customer Table Booking - Requirement 3  
Requirement 3:  
In this requirement, you need to validate the name and age of a customer. Also, you need to  
find if the customer is lucky or not.  
i) The name should contain only alphabets and not numbers or special characters.  
ii) The age is considered valid only if it is greater than equal to 18.(Take the current date as  
"01-01-2018")  
iii) A customer is said to be lucky if the repetitive sum of his mobile number is equal to 1.  
Ex:- Mobile number 9635285233 is lucky.  
step1- 9+6+3+5+2+8+5+2+3+3 - 46  
step 2 - 4+6 - 10  
step 3 - 1+0 - 1  
a)Create a Class Main with the following static methods:  
Method Name  
Description  
This method accepts java  
argument and returns a bo  
Calculate the age and retu  
age of the customer is gre  
equal to 18, else return Fa  
static Boolean validateAge(java.util.Date birth)  
This method accepts a Str  
argument and returns a bo  
the name of the customer  
return True if the name is  
returnFalse  
static Boolean validateName(String name)  
This method accepts a Str  
argument and returns a bo  
whether the mobile numbe  
customer is lucky and retu  
return False  
static Boolean validateLuckyCustomer(String mobile)  
Print the following statements in the main method.  
Print "Age is valid" if the age is greater than or equal to18, else print "Age is invalid".  
Print "Name is valid" if the name contains only alphabets (a-z) or (A-Z), else print "Name is  
invalid".  
Print "Lucky Customer" if the sum of the digits of the mobile number is 1, else print "Unlucky  
Customer".  
Sample Input and Output 1:  
1
2
3
.Validate Age  
.Validate Name  
.Lucky Customer  
Enter your choice:  
1
Enter birthdate:  
2
5-12-1989  
Age is valid  
Sample Input and Output 2:  
1
2
3
.Validate Age  
.Validate Name  
.Lucky Customer  
Enter your choice:  
1
Enter birthdate:  
2
9-02-2000  
Age is invalid  
Sample Input and Output 3:  
1
2
3
.Validate Age  
.Validate Name  
.Lucky Customer  
Enter your choice:  
2
Enter name:  
Jane  
Name is valid  
Sample Input and Output 4:  
1
2
3
.Validate Age  
.Validate Name  
.Lucky Customer  
Enter your choice:  
2
Enter name:  
Jane Doe  
Name is invalid  
Sample Input and Output 5:  
1
2
3
.Validate Age  
.Validate Name  
.Lucky Customer  
Enter your choice:  
3
Enter mobile number:  
9
597074311  
Lucky Customer  
Sample Input and Output 6:  
1
2
3
.Validate Age  
.Validate Name  
.Lucky Customer  
Enter your choice:  
3
Enter mobile number:  
9
876543210  
Unlucky Customer  
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.time.LocalDate;  
import java.time.Period;  
import java.time.format.DateTimeFormatter;  
import java.util.Date;  
import java.util.regex.Matcher;  
import java.util.regex.Pattern;  
public class Main {  
public static void main(String args[]) throws IOException, ParseException {  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
System.out.println("1.Validate Age\n2.Validate Name\n3.Lucky Customer\nEnter your choice:");  
Integer choice=Integer.parseInt(br.readLine());  
if(choice==1) {  
System.out.println("Enter birthdate:");  
/
/fill your code  
String bd=br.readLine();  
Date birthDate=sdf.parse(bd);  
if(validateAge(birthDate))  
{
System.out.println("Age is valid");  
}
else  
System.out.println("Age is invalid");  
}
if(choice==2) {  
System.out.println("Enter name:");  
/
/fill your code  
String name=br.readLine();  
if(validateName(name))  
{
System.out.println("Name is valid");  
}
else  
System.out.println("Name is invalid");  
}
if(choice==3) {  
System.out.println("Enter mobile number:");  
/
/fill your code  
String mobile=br.readLine();  
if(validateLuckyCustomer(mobile))  
{
System.out.println("Lucky Customer");  
}
else  
System.out.println("Unlucky Customer");  
}
}
public static Boolean validateAge(Date birthDate) throws ParseException{  
/
/fill your code  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy");  
String curr="01-01-2018";  
LocalDate currdate=LocalDate.parse(curr,format);  
LocalDate bdate=LocalDate.parse(sdf.format(birthDate),format);  
Period p=Period.between(currdate,bdate);  
if(!(Math.abs(p.getYears())>=18))  
{
return false;  
}
else  
return true;  
}
public static Boolean validateName(String name){  
/
/fill your code  
for(int i=0;i<name.length();i++){  
if(!(Character.isAlphabetic(name.charAt(i))))  
{
return false;  
}
}
return true;  
}
public static Boolean validateLuckyCustomer(String mobile){  
/
/fill your code  
int sum=0;int num=0;  
for(int i=0;i<mobile.length();i++)  
{
sum=sum+Integer.parseInt(Character.toString(mobile.charAt(i)));  
while(sum>9)  
{
num=sum%10;  
sum=sum/10;  
sum=sum+num;  
}
}
if(sum!=1)  
{
return false;  
}
else  
return true;  
}
}
Page of  
Customer Table Booking - Requirement 4  
Requirement 4:  
In this requirement, you need to sort the list of customers by name, amount or rating using  
Comparable and Comparator interfaces.  
a) Create a Customer Class with the following private attributes:  
Member Field Name  
id  
Type  
Long  
name  
String  
mobileNumber  
birthdate  
String  
java.util.Date  
Double  
Double  
java.util.Date  
Double  
averageSpendAmount  
totalAmount  
dateEnrolled  
rating  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order: Customer(Long id, String name, StringmobileNumber, java.util.Date  
birthdate, Double averageSpendAmount, Double totalAmount, java.util.Date dateEnrolled,  
Double rating)  
b) The Customer class should implement the Comparableinterface which sorts the  
customer list based on names.  
c) Write a Comparator class namedAmountComparator implementing Comparator  
Interface. This comparator should sort the customers based on the  
averageSpendAmount.  
d) Write a Comparator class namedRatingComparator implementing Comparator  
Interface. This comparator should sort the customers based on their rating.  
The input format consists of customer details separated by comma in the below order,  
(
id, name, mobileNumber, birthdate, averageSpendAmount, totalAmount, dateEnrolled,  
rating)  
Note: If any other option is selected display "Invalid choice".  
Assume that name,amount spent and rating will be always unique.  
When the “customer” object is printed, it should display the following format  
Print format:  
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n",  
"
Id","Name","Mobile Number","Date of Birth","Average spent amount","Total  
amount","Date Enrolled","Rating");  
Sample INPUT & OUTPUT 1:  
Enter the number of customers:  
3
2
1
3
22,John,9876543210,12-12-1990,4000,12000.5,12-12-2017,3.5  
11,Mark,9632587410,13-01-1992,3000.0,8000,14-04-2014,4  
33,Anil,9874563012,19-09-2015,6000.0,5000,16-09-2016,3.75  
Enter a type to sort:  
1
2
3
1
.Name  
.Amount Spent  
.Rating  
Id Name  
Mobile Number Date of Birth Average spent amount Total amount  
Date Enrolled Rating  
3
2
2
2
1
2
33 Anil  
9874563012  
9876543210  
9632587410  
19-09-2015  
12-12-1990  
13-01-1992  
6000.0  
4000.0  
3000.0  
5000.0  
12000.5  
8000.0  
16-09-  
12-12-  
016  
3.75  
22 John  
017  
3.5  
11 Mark  
14-04-  
014  
4.0  
Sample INPUT & OUTPUT 2:  
Enter the number of customers:  
3
2
1
3
22,John,9876543210,12-12-1990,4000,12000.5,12-12-2017,3.5  
11,Mark,9632587410,13-01-1992,3000.0,8000,14-04-2014,4  
33,Anil,9874563012,19-09-2015,6000.0,5000,16-09-2016,3.75  
Enter a type to sort:  
1
2
3
2
.Name  
.Amount Spent  
.Rating  
Id Name  
Mobile Number Date of Birth Average spent amount Total amount  
Date Enrolled Rating  
1
2
2
2
3
2
11 Mark  
9632587410  
9876543210  
9874563012  
13-01-1992  
12-12-1990  
19-09-2015  
3000.0  
4000.0  
6000.0  
8000.0  
12000.5  
5000.0  
14-04-  
12-12-  
16-09-  
014  
4.0  
22 John  
017  
3.5  
33 Anil  
016  
3.75  
Sample INPUT & OUTPUT 3:  
Enter the number of customers:  
3
2
1
3
22,John,9876543210,12-12-1990,4000,12000.5,12-12-2017,3.5  
11,Mark,9632587410,13-01-1992,3000.0,8000,14-04-2014,4  
33,Anil,9874563012,19-09-2015,6000.0,5000,16-09-2016,3.75  
Enter a type to sort:  
1
2
3
3
.Name  
.Amount Spent  
.Rating  
Id Name  
Mobile Number Date of Birth Average spent amount Total amount  
Date Enrolled Rating  
2
2
3
2
1
2
22 John  
9876543210  
9874563012  
9632587410  
12-12-1990  
19-09-2015  
13-01-1992  
4000.0  
6000.0  
3000.0  
12000.5  
5000.0  
12-12-  
16-09-  
14-04-  
017  
3.5  
33 Anil  
016  
3.75  
11 Mark  
8000.0  
014  
4.0  
Sample INPUT & OUTPUT 4:  
Enter the number of customers:  
3
2
1
3
22,John,9876543210,12-12-1990,4000,12000.5,12-12-2017,3.5  
11,Mark,9632587410,13-01-1992,3000.0,8000,14-04-2014,4  
33,Anil,9874563012,19-09-2015,6000.0,5000,16-09-2016,3.75  
Enter a type to sort:  
1
2
3
4
.Name  
.Amount Spent  
.Rating  
Invalid choice  
import java.util.Date;  
public class Customer implements Comparable<Customer> {  
//fill the code  
private Long id;  
private String name;  
private String mobileNumber;  
private java.util.Date birthdate;  
private Double averageSpendAmount;  
private Double totalAmount;  
private java.util.Date dateEnrolled;  
private Double rating;  
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public String getMobileNumber() {  
return mobileNumber;  
}
public void setMobileNumber(String mobileNumber) {  
this.mobileNumber = mobileNumber;  
}
public java.util.Date getBirthdate() {  
return birthdate;  
}
public void setBirthdate(java.util.Date birthdate) {  
this.birthdate = birthdate;  
}
public Double getAverageSpendAmount() {  
return averageSpendAmount;  
}
public void setAverageSpendAmount(Double averageSpendAmount) {  
this.averageSpendAmount = averageSpendAmount;  
}
public Double getTotalAmount() {  
return totalAmount;  
}
public void setTotalAmount(Double totalAmount) {  
this.totalAmount = totalAmount;  
}
public java.util.Date getDateEnrolled() {  
return dateEnrolled;  
}
public void setDateEnrolled(java.util.Date dateEnrolled) {  
this.dateEnrolled = dateEnrolled;  
}
public Double getRating() {  
return rating;  
}
public void setRating(Double rating) {  
this.rating = rating;  
}
public Customer(Long id, String name, String mobileNumber, Date birthdate,  
Double averageSpendAmount, Double totalAmount, Date dateEnrolled,  
Double rating) {  
this.name = name;  
this.mobileNumber = mobileNumber;  
this.birthdate = birthdate;  
this.averageSpendAmount = averageSpendAmount;  
this.totalAmount = totalAmount;  
this.dateEnrolled = dateEnrolled;  
this.rating = rating;  
}
public Customer() {  
super();  
}
@
Override  
public int compareTo(Customer c) {  
return this.name.compareTo(c.name);  
}
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Collections;  
import java.util.List;  
public class Main {  
public static void main(String[] args) throws IOException, NumberFormatException, ParseException  
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
List<Customer> list=new ArrayList<Customer>();  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
System.out.println("Enter the number of customers:");  
int n=Integer.parseInt(br.readLine());  
for(int i=1;i<=n;i++){  
String split=br.readLine();  
String splitted[]=split.split(",");  
list.add(new  
Customer(Long.parseLong(splitted[0]),splitted[1],splitted[2],sdf.parse(splitted[3]),Double.parseDoubl  
e(splitted[4]),Double.parseDouble(splitted[5]),sdf.parse(splitted[6]),  
Double.parseDouble(splitted[7])));  
}
System.out.println("Enter a type to sort:\n1.Name\n2.Amount Spent\n3.Rating");  
int choice=Integer.parseInt(br.readLine());  
//fill the code  
switch(choice)  
{
case 1:  
Collections.sort(list);  
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n", "Id","Name","Mobile  
Number","Date of Birth","Average spent amount","Total amount","Date Enrolled","Rating");  
for(Customer c:list)  
{
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s  
%s\n",c.getId(),c.getName(),c.getMobileNumber(),sdf.format(c.getBirthdate()),c.getAverageSpendA  
mount(),c.getTotalAmount(),sdf.format(c.getDateEnrolled()),c.getRating());  
}
break;  
case 2:  
Collections.sort(list,new AmountComparator());  
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n", "Id","Name","Mobile  
Number","Date of Birth","Average spent amount","Total amount","Date Enrolled","Rating");  
for(Customer c:list)  
{
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s  
%s\n",c.getId(),c.getName(),c.getMobileNumber(),sdf.format(c.getBirthdate()),c.getAverageSpendA  
mount(),c.getTotalAmount(),sdf.format(c.getDateEnrolled()),c.getRating());  
}
break;  
case 3:  
Collections.sort(list,new RatingComparator());  
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s %s\n", "Id","Name","Mobile  
Number","Date of Birth","Average spent amount","Total amount","Date Enrolled","Rating");  
for(Customer c:list)  
{
System.out.format("%-5s %-15s %-15s %-15s %-20s %-15s %-15s  
%s\n",c.getId(),c.getName(),c.getMobileNumber(),sdf.format(c.getBirthdate()),c.getAverageSpendA  
mount(),c.getTotalAmount(),sdf.format(c.getDateEnrolled()),c.getRating());  
}
break;  
default:  
System.out.println("Invalid choice");  
break;  
}
}
}
import java.util.Comparator;  
public class RatingComparator implements Comparator<Customer> {  
@
Override  
public int compare(Customer c1, Customer c2) {  
/ TODO Auto-generated method stub  
/
if(c1.getRating()>c2.getRating())  
return 1;  
else if(c1.getRating()<c2.getRating())  
return -1;  
else  
return 0;  
}
//fill the code  
}
import java.util.Comparator;  
public class AmountComparator implements Comparator<Customer>{  
@
Override  
public int compare(Customer a1, Customer a2) {  
/ TODO Auto-generated method stub  
/
if(a1.getAverageSpendAmount()>a2.getAverageSpendAmount())  
return 1;  
else if(a1.getAverageSpendAmount()<a2.getAverageSpendAmount())  
return -1;  
else  
return 0;  
}
//fill the code  
}
In this requirement, build a feature in which user can book tables. If the table is not  
available suggest alternate tables in ascending order of table number.  
a) Create a Booking Class with the following private attributes:  
Member Field Name  
id  
Type  
Long  
customerName  
table  
String  
Table  
membersPresent  
billamount  
Integer  
Double  
java.util.Date  
bookingTime  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order:Booking(Long id, String customerName, Table table, Integer  
membersPresent, Double billamount, Date bookingTime)  
b) Create a Table Class with the following private attributes:  
Member Field Name  
Type  
id  
Long  
number  
capacity  
Integer  
Integer  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order:Table(Long id, Integer number, Integer capacity)  
c) The Table class should implement the Comparable interface which sorts the table  
list based on table number.  
d) Create the following static methods in the Table class,  
Method Name  
Description  
static Table  
createTable(String line)  
This method accepts a String and returns a table object. The csv String is  
passed as value. Split the value, then create a table object and return it.  
e) Create the following static methods in the Booking class,  
Method Name  
Description  
This method accepts a list of table, booking list, and a booking  
detail from the user as arguments. Check if the table is already  
booked or not from bookinglist. If the table is not booked create  
Booking object and add it to the booking list and display "Table  
successfully booked", if it is already booked display "Sorry the  
static void createBooking(List<Table>  
tableList,List<Booking>  
bookingList,String line)  
table is not available" followed by the available table details.  
Note: The list of available tables and status of booking are displayed within the  
function.  
The input format of Table details are separated by comma in the below order,  
(
id, number, capacity)  
The input format of Booking details are separated by comma in the below order,  
id, customerName, tableNumber, membersPresent, billamount, bookingTime)  
(
When the “table” object is printed, it should display the following format  
Print format:  
System.out.format("%-5s %-10s %s\n","ID","Number","Capacity");  
Sample INPUT & OUTPUT 1:  
Enter the number of tables:  
2
1
1
01,10,10  
02,20,15  
Enter the booking details:  
0,John,10,8,1200,12-01-2018  
1
Table successfully booked  
Do you want to continue(yes/no)  
yes  
Enter the booking details:  
2
0,Peter,2,9,1300,12-01-2018  
Sorry the table is not available  
The available tables are:  
ID Number Capacity  
1
02 20  
15  
Do you want to continue(yes/no)  
yes  
Enter the booking details:  
2
0,Peter,10,8,1300,12-01-2018  
Sorry the table is not available  
The available tables are:  
ID Number Capacity  
1
02 20  
15  
Do you want to continue(yes/no)  
yes  
Enter the booking details:  
2
0,Peter,20,8,1300,12-01-2018  
Table successfully booked  
Do you want to continue(yes/no)  
no  
Main  
import java.io.BufferedReader;  
import java.io.InputStreamReader;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.List;  
public class Main {  
public static void main(String args[]) throws Exception{  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
List<Table> tableList=new ArrayList<Table>();  
List<Booking> bookingList=new ArrayList<Booking>();  
String choice="";  
System.out.println("Enter the number of tables:");  
Integer count=Integer.parseInt(br.readLine());  
for(int i=0;i<count;i++)  
tableList.add(Table.createTable(br.readLine()));  
do  
{
System.out.println("Enter the booking details:");  
Booking.createBooking(tableList, bookingList, br.readLine());  
System.out.println("Do you want to continue(yes/no)");  
choice=br.readLine();  
}
while(choice.equalsIgnoreCase("yes"));  
}
}
Table  
public class Table  
{
Long id ;  
Integer number;  
Integer capacity;  
public Table() {  
super();  
}
public Table(Long id, Integer number, Integer capacity) {  
super();  
this.id = id;  
this.number = number;  
this.capacity = capacity;  
}
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public Integer getNumber() {  
return number;  
}
public void setNumber(Integer number) {  
this.number = number;  
}
public Integer getCapacity() {  
return capacity;  
}
public void setCapacity(Integer capacity) {  
this.capacity = capacity;  
}
public static Table createTable(String line)  
{
Table tab=null;  
String in[]=line.split(",");  
return tab=new  
Table(Long.parseLong(in[0]),Integer.parseInt(in[1]),Integer.parseInt(in[2]));  
}
}
Booking  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Collections;  
import java.util.Date;  
import java.util.List;  
public class Booking  
{
Long id ;  
String customerName;  
Table table;  
Integer membersPresent;  
Double billamount;  
Date bookingTime;  
public Booking() {  
super();  
}
public Booking(Long id, String customerName, Table table,  
Integer membersPresent, Double billamount, Date bookingTime) {  
super();  
this.id = id;  
this.customerName = customerName;  
this.table = table;  
this.membersPresent = membersPresent;  
this.billamount = billamount;  
this.bookingTime = bookingTime;  
}
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getCustomerName() {  
return customerName;  
}
public void setCustomerName(String customerName) {  
this.customerName = customerName;  
}
public Table getTable() {  
return table;  
}
public void setTable(Table table) {  
this.table = table;  
}
public Integer getMembersPresent() {  
return membersPresent;  
}
public void setMembersPresent(Integer membersPresent) {  
this.membersPresent = membersPresent;  
}
public Double getBillamount() {  
return billamount;  
}
public void setBillamount(Double billamount) {  
this.billamount = billamount;  
}
public Date getBookingTime() {  
return bookingTime;  
}
public void setBookingTime(Date bookingTime) {  
this.bookingTime = bookingTime;  
}
public static void createBooking(List<Table> tableList,List<Booking> bookingList,String  
line) throws Exception  
{
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
String in[]=line.split(",");  
boolean flag=true;  
for(Table tab:tableList)  
{
if(tab.getNumber()==Integer.parseInt(in[2]))  
{
Booking book=new  
Booking(Long.parseLong(in[0]),in[1],tab,Integer.parseInt(in[3]),Double.parseDouble(in[4  
]
),sdf.parse(in[5]));  
tableList.remove(tab);  
bookingList.add(book);  
System.out.println("Table successfully booked");  
break;  
}
else flag=false;  
}
if(!flag)  
{
System.out.println("Sorry the table is not available\nThe available tables are:");  
System.out.format("%-5s %-10s %s\n","ID","Number","Capacity");  
for(Table tab:tableList)  
System.out.format("%-5s %-10s %s\n",tab.getId(),tab.getNumber(),tab.getCapacity());  
}
}
}
Page of  
Customer Table Booking - Requirement 6  
Requirement 6:  
In this requirement, build a feature in which your friend will be able to see the amount of income  
gained on a daily basis.  
a) Create a Booking Class with the following private attributes:  
Member Field Name  
id  
Type  
Long  
customerName  
tableNumber  
membersPresent  
billamount  
String  
Integer  
Integer  
Double  
java.util.Date  
bookingTime  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters,Add a  
default constructor and a parameterized constructor to take in all attributes in the given  
order: Booking(Long id, String customerName, Integer tableNumber, Integer  
membersPresent, Double billamount, Date bookingTime)  
b) Create the following static method ofBooking class,  
Method Name  
Description  
This method will accept a list of booking objects as an argum  
Create a map which contains the booking time as key(java.u  
total amount for the Booking(Double) as value.  
static Map<Date,Double>  
calculateDayBilling(List<Booking> bookings) In this method iterate through the booking list and build a m  
having booking time as key and the total amount for particu  
value and return it.  
The input format of Booking details is separated by comma in the below order,  
(id, customerName, tableNumber, membersPresent, billamount, bookingTime)  
Print the map details in the below format.  
Print format:  
System.out.format("%-20s %s\n","Date","Amount");  
Note: The final details are printed in the main method. Display the details in ascending order of  
days. Display the amount correct to one decimal.  
Sample INPUT & OUTPUT:  
Enter the number of booking details:  
5
1
2
3
4
5
0,John,10,8,1200,12-01-2018  
0,Peter,20,8,1300,13-01-2018  
0,Starc,30,4,1200,13-01-2018  
0,Mark,10,4,900,14-01-2018  
0,Jack,30,2,500,14-01-2018  
Date  
Amount  
1200.0  
2500.0  
1400.0  
1
1
1
2-01-2018  
3-01-2018  
4-01-2018  
import java.util.Date;  
import java.util.List;  
import java.util.Map;  
import java.util.TreeMap;  
public class Booking {  
//fill the code  
private Long id;  
private String customerName;  
private Integer tableNumber;  
private Integer membersPresent;  
private Double billamount;  
private java.util.Date bookingTime;  
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getCustomerName() {  
return customerName;  
}
public void setCustomerName(String customerName) {  
this.customerName = customerName;  
}
public Integer getTableNumber() {  
return tableNumber;  
}
public void setTableNumber(Integer tableNumber) {  
this.tableNumber = tableNumber;  
}
public Integer getMembersPresent() {  
return membersPresent;  
}
public void setMembersPresent(Integer membersPresent) {  
this.membersPresent = membersPresent;  
}
public Double getBillamount() {  
return billamount;  
}
public void setBillamount(Double billamount) {  
this.billamount = billamount;  
}
public java.util.Date getBookingTime() {  
return bookingTime;  
}
public void setBookingTime(java.util.Date bookingTime) {  
this.bookingTime = bookingTime;  
}
public Booking(Long id, String customerName, Integer tableNumber,  
Integer membersPresent, Double billamount, Date bookingTime) {  
this.id = id;  
this.customerName = customerName;  
this.tableNumber = tableNumber;  
this.membersPresent = membersPresent;  
this.billamount = billamount;  
this.bookingTime = bookingTime;  
}
public Booking() {  
super();  
}
public static Map<Date,Double> calculateDayBilling(List<Booking> bookings){  
/
/fill the code  
Map<Date,Double> cmap=new TreeMap<Date,Double>();  
for(Booking b:bookings)  
{
if(cmap.containsKey(b.getBookingTime()))  
{
Double q=cmap.get(b.getBookingTime());  
q=q+b.getBillamount();  
cmap.put(b.getBookingTime(), q);  
}
else  
cmap.put(b.getBookingTime(), b.getBillamount());  
}
return cmap;  
}
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
import java.util.Map;  
public class Main {  
public static void main(String[] args) throws IOException, ParseException {  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
List<Booking> bookings=new ArrayList<>();  
Booking b=new Booking();  
System.out.println("Enter the number of booking details:");  
int n=Integer.parseInt(br.readLine());  
//fill the code  
for(int i=0;i<n;i++)  
{
String bdetail=br.readLine();  
String s1[]=bdetail.split(",");  
b=new  
Booking(Long.parseLong(s1[0]),s1[1],Integer.parseInt(s1[2]),Integer.parseInt(s1[3]),Double.pars  
eDouble(s1[4]),sdf.parse(s1[5]));  
bookings.add(b);  
}
Map <Date,Double> map=Booking.calculateDayBilling(bookings);  
System.out.format("%-20s %s\n","Date","Amount");  
/
/fill the code  
for(Date d:map.keySet())  
{
System.out.format("%-20s %.1f\n",sdf.format(d),map.get(d));  
}
}
}
Mail Folder - Requirement 1  
You work for a start-up company. The company has been using an outdated mail  
system. Looking at the difficulty in the old system, the management decided to build  
their own mail server. There are two major domains, Mail and Mail Folder. The mail  
details are stored in the mail domain. The mail folder is used to group the emails  
together.  
Requirement 1:  
Let’s start off by creating two Mail objects and check whether they are equal.  
1
. Create a Mail Class with the following attributes:  
Member Field Name  
Type  
id  
Long  
to  
String  
from  
String  
subject  
content  
receivedDate  
size  
String  
String  
java.util.Date  
Double  
2
3
4
. Mark all the attributes as private  
. Create / Generate appropriate Getters & Setters  
. Add a default constructor and a parameterized constructor to take in all attributes  
in the given order: Mail(Long id, String to, String from, String subject,  
String content, Date receivedDate,Double size)  
5
. When the “mail” object is printed, it should display the following details:  
[
Override the toString method]  
Print format:  
Id:"id"  
To:"to"  
From:"from"  
Subject:"subject"  
Content:"content"  
Received Date:"receivedDate"  
Size:"size"  
6
. Two emails are considered same if they have the same to address, from  
address, and subject. Implement the logic in the appropriate function. (Case –  
Insensitive) [Override the equals method]  
The input format consists of mail details separated by comma in the below order,  
(
id,to, from,subject,content,receivedDate,size)  
The Input to your program would be details of two emails, you need to display their  
details as given in "5th point(refer above)" and compare the two emails and display if  
the Mails are same or different.  
Note: There is an empty line between display statements. Print the empty lines in main  
function.  
Display one digit after the decimal point for Double datatype.  
Sample INPUT & OUTPUT 1:  
Enter mail 1 detail:  
1
0
001,meyyappan@gmail.com,satish@gmail.com,Master Copy,Attached doc,05-  
5-2017,10.0  
Enter mail 2 detail:  
1
001,meyyappan@gmail.com,satish@gmail.com,Master Copy,Attached doc,05-  
0
5-2017,10.0  
Mail 1:  
Id:1001  
To:meyyappan@gmail.com  
From:satish@gmail.com  
Subject:Master Copy  
Content:Attached doc  
ReceivedDate:05-05-2017  
Size:10.0  
Mail 2:  
Id:1001  
To:meyyappan@gmail.com  
From:satish@gmail.com  
Subject:Master Copy  
Content:Attached doc  
ReceivedDate:05-05-2017  
Size:10.0  
Mail 1 is same as Mail 2  
Sample INPUT & OUTPUT 2:  
Enter mail 1 detail:  
1
2
001,meyyappan@gmail.com,satish@gmail.com,Master Copy,Attached doc,05-05-  
017,10.0  
Enter mail 2 detail:  
1
2
002,satish@gmail.com,meyyappan@gmail.com,Master Copy,Attached doc,05-05-  
017,10.0  
Mail 1:  
Id:1001  
To:meyyappan@gmail.com  
From:satish@gmail.com  
Subject:Master Copy  
Content:Attached doc  
ReceivedDate:05-05-2017  
Size:10.0  
Mail 2:  
Id:1002  
To:satish@gmail.com  
From:meyyappan@gmail.com  
Subject:Master Copy  
Content:Attached doc  
ReceivedDate:05-05-2017  
Size:10.0  
Mail 1 and Mail 2 are different  
import java.text.SimpleDateFormat;  
import java.util.Date;  
public class Mail {  
/
/Your code goes here...  
private Long id;  
private String to,from,subject,content;  
private java.util.DatereceivedDate;  
private Double size;  
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getTo() {  
return to;  
}
public void setTo(String to) {  
this.to = to;  
}
public String getFrom() {  
return from;  
}
public void setFrom(String from) {  
this.from = from;  
}
public String getSubject() {  
return subject;  
}
public void setSubject(String subject) {  
this.subject = subject;  
}
public String getContent() {  
return content;  
}
public void setContent(String content) {  
this.content = content;  
}
public java.util.DategetReceivedDate() {  
return receivedDate;  
}
public void setReceivedDate(java.util.DatereceivedDate) {  
this.receivedDate = receivedDate;  
}
public Double getSize() {  
return size;  
}
public void setSize(Double size) {  
this.size = size;  
}
public Mail(Long id, String to, String from, String subject,  
String content, Date receivedDate, Double size) {  
super();  
this.id = id;  
this.to = to;  
this.from = from;  
this.subject = subject;  
this.content = content;  
this.receivedDate = receivedDate;  
this.size = size;  
}
public Mail() {  
super();  
}
@Override  
public inthashCode() {  
final int prime = 31;  
int result = 1;  
result = prime * result + ((from == null) ?0 :from.hashCode());  
result = prime * result + ((subject == null) ?0 :subject.hashCode());  
result = prime * result + ((to == null) ?0 :to.hashCode());  
return result;  
}
@Override  
public booleanequals(Object obj) {  
if (this == obj)  
return true;  
if (obj == null)  
return false;  
if (getClass() != obj.getClass())  
return false;  
Mail other = (Mail) obj;  
if (from == null) {  
if (other.from != null)  
return false;  
else if (!from.equals(other.from))  
return false;  
}
if (subject == null) {  
if (other.subject != null)  
return false;  
else if (!subject.equals(other.subject))  
return false;  
}
if (to == null) {  
if (other.to != null)  
return false;  
else if (!to.equals(other.to))  
return false;  
}
return true;  
}
@Override  
public String toString() {  
SimpleDateFormatsdf=new SimpleDateFormat("dd-MM-yyyy");  
return  
"Id:"+id+"\nTo:"+to+"\nFrom:"+from+"\nSubject:"+subject+"\nContent:"+content+"\nReceivedDate:"+s  
df.format(receivedDate)+"\nSize:"+size;  
}
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
public class Main {  
public static void main(String []args) throws IOException, NumberFormatException,  
ParseException {  
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));  
/
/Your code goes here...  
SimpleDateFormatsdf=new SimpleDateFormat("dd-MM-yyyy");  
Mail m[]=new Mail[2];  
System.out.println("Enter mail 1 detail:");  
/
/Your code goes here...  
String m1=reader.readLine();  
String s[]=m1.split(",");  
m[0]=new  
Mail(Long.parseLong(s[0]),s[1],s[2],s[3],s[4],sdf.parse(s[5]),Double.parseDouble(s[6]));  
System.out.println("Enter mail 2 detail:");  
/Your code goes here...  
/
String m2=reader.readLine();  
String a[]=m2.split(",");  
m[1]=new  
Mail(Long.parseLong(a[0]),a[1],a[2],a[3],a[4],sdf.parse(a[5]),Double.parseDouble(a[6]));  
for(inti=0;i<2;i++)  
{
System.out.println("Mail "+(i+1)+":");  
System.out.println(m[i]);  
}
if(m[0].equals(m[1]))  
{
System.out.println("Mail 1 is same as Mail 2");  
}
else  
System.out.println("Mail 1 and Mail 2 are different");  
}
}
Page of  
Mail Folder - Requirement 2  
Requirement 2:  
Now we are gonna start creating a folder and add mail to it. Start with creating a folder  
and use menu-driven approach to add, remove, display details of the mail in the folder.  
a)Create a Class Mail with the following attributes:  
Member Field Name  
Type  
id  
Long  
from  
String  
to  
String  
subject  
content  
receivedDate  
size  
String  
String  
java.util.Date  
Double  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order: public Mail(Long id, String from, String to, String subject, String  
content, Date receivedDate, Double size)  
b)Create a Class MailFolder with the following attributes:  
Member Field Name  
name  
Type  
String  
mailList  
ArrayList<Mail>  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order: MailFolder(String name, List<Mail>mailList). In constructor pass the  
mailList value as an empty list. Only one folder will be present at a time.  
c) Create the following static method in Mail class,  
Method Name  
Description  
public static Mail  
createMail(String detail)  
This method accepts a string which contains mail details separated by c  
Split the details and create a mail object from the details and return it.  
The mail details should be given as a comma-separated value in the below order,  
id,from,to, subject, content, receivedDate, size  
d) Create the following methods in MailFolder class,  
Method Name  
Description  
public void addMailToFolder(Mail  
mail)  
This method accepts a mail object and add the mail to the mail  
current mail folder.  
This method will get the id of the mail and delete the mail with th  
specified id from the current folder.  
public Boolean  
removeMailFromFolder(Long id)  
If a mail with the given id found, delete the mail and return true.  
with the id is not found return false.  
This method will display the mail list in the current folder.  
If the mail list is empty display "No mails to show", else  
display "Mails in [folder name]" and display all the mail details in  
specified format. Where [folder name] specifies the name of the  
public void displayMails()  
After deletion, if true is returned print "Mail successfully deleted", else print "Mail not  
found in the folder". After adding mail to the folder, print "Mail successfully added".  
Note: The above print statements should be present in the main method.  
When the “mail” object is printed, it should display the following format  
Print format:  
String.format("%-10s%-15s%-15s%-15s%-20s%-15s%-10s\n",  
"
Id","From","To","Subject","Content","ReceivedDate","Size"); Display 1 digit  
after decimal point in Double.  
Sample Input and Output:  
Enter the name of the folder:  
Inbox  
1
2
3
4
.Add Mail  
.Delete Mail  
.Display Mails  
.Exit  
Enter your choice:  
3
No mails to show  
1
2
3
4
.Add Mail  
.Delete Mail  
.Display Mails  
.Exit  
Enter your choice:  
1
Enter the details of mail in CSV format:  
1
2,john@abc.in,jane@abc.in,Hi,Happy New Year,01-01-2018,10  
Mail successfully added  
1
2
3
4
.Add Mail  
.Delete Mail  
.Display Mails  
.Exit  
Enter your choice:  
1
Enter the details of mail in CSV format:  
1
6,jack@abc.in,jane@abc.in,Hi,Happy Pongal,14-01-2018,15  
Mail successfully added  
1
2
3
4
.Add Mail  
.Delete Mail  
.Display Mails  
.Exit  
Enter your choice:  
3
Mails in Inbox  
Id  
From  
To  
Subject  
Content Received Date Size  
Happy New Year  
Happy Pongal  
1
1
1
2
3
4
2
6
john@abc.in jane@abc.in Hi  
jack@abc.in jane@abc.in Hi  
01-01-2018 10.0  
14-01-2018 15.0  
.Add Mail  
.Delete Mail  
.Display Mails  
.Exit  
Enter your choice:  
2
Enter the id of the mail to be deleted:  
1
3
Mail not found in the folder  
1
2
3
4
.Add Mail  
.Delete Mail  
.Display Mails  
.Exit  
Enter your choice:  
2
Enter the id of the mail to be deleted:  
1
6
Mail successfully deleted  
1
2
3
4
.Add Mail  
.Delete Mail  
.Display Mails  
.Exit  
Enter your choice:  
3
Mails in Inbox  
Id  
From  
To  
Subject  
Content  
Received Date Size  
01-01-2018 10.0  
1
2
john@abc.in jane@abc.in Hi  
Happy New Year  
1
2
3
4
.Add Mail  
.Delete Mail  
.Display Mails  
.Exit  
Enter your choice:  
4
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.util.ArrayList;  
public class Main {  
public static void main(String args[]) throws NumberFormatException, IOException, ParseException {  
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));  
System.out.println("Enter the name of the folder:");  
MailFolder mf=new MailFolder(br.readLine(),new ArrayList<Mail>());  
Integer choice=0;  
do  
{
System.out.println("1.Add Mail\n2.Delete Mail\n3.Display Mails\n4.Exit\nEnter your choice:");  
choice=Integer.parseInt(br.readLine());  
if(choice==1) {  
System.out.println("Enter the details of mail in CSV format:");  
String detail=br.readLine();  
Mail m=Mail.createMail(detail);  
mf.addMailToFolder(m);  
System.out.println("Mail successfully added");  
}
else if(choice==2) {  
System.out.println("Enter the id of the mail to be deleted:");  
Long id=Long.parseLong(br.readLine());  
if(mf.removeMailFromFolder(id))  
{
System.out.println("Mail successfully deleted");  
}
else  
{
System.out.println("Mail not found in the folder");  
}
}
else if(choice==3) {  
mf.displayMails();  
}
else if(choice==4)  
{
System.exit(0);  
}
}while(choice>0&&choice<4);  
}
}
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Date;  
public class Mail {  
Long id;  
String to;  
String from;  
String subject;  
String content;  
Date receivedDate;  
Double size;  
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getTo() {  
return to;  
}
public void setTo(String to) {  
this.to = to;  
}
public String getFrom() {  
return from;  
}
public void setFrom(String from) {  
this.from = from;  
}
public String getSubject() {  
return subject;  
}
public void setSubject(String subject) {  
this.subject = subject;  
}
public String getContent() {  
return content;  
}
public void setContent(String content) {  
this.content = content;  
}
public Date getReceivedDate() {  
return receivedDate;  
}
public void setReceivedDate(Date receivedDate) {  
this.receivedDate = receivedDate;  
}
public Double getSize() {  
return size;  
}
public void setSize(Double size) {  
this.size = size;  
}
public Mail(){}  
public Mail(Long id, String to, String from, String subject,  
String content, Date receivedDate, Double size) {  
this.id = id;  
this.to = to;  
this.from = from;  
this.subject = subject;  
this.content = content;  
this.receivedDate = receivedDate;  
this.size = size;  
}
public static Mail createMail(String detail) throws NumberFormatException, ParseException  
{
SimpleDateFormatsdf=new SimpleDateFormat("dd-MM-yyyy");  
String a[]=detail.split(",");  
Mail m=new Mail(Long.parseLong(a[0]),a[1],a[2],a[3],a[4],sdf.parse(a[5]),Double.parseDouble(a[6]));  
return m;  
}
@
Override  
public String toString() {  
SimpleDateFormatsdf=new SimpleDateFormat("dd-MM-yyyy");  
return String.format("%-10s%-15s%-15s%-15s%-20s%-15s%-10s\n",id,to,from,subject,  
content,sdf.format(receivedDate),size);  
}
}
import java.util.ArrayList;  
public class MailFolder  
{
String name;  
ArrayList<Mail>mailList;  
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public ArrayList<Mail>getMailList() {  
return mailList;  
}
public void setMailList(ArrayList<Mail>mailList) {  
this.mailList = mailList;  
}
public MailFolder(){}  
public MailFolder(String name, ArrayList<Mail>mailList) {  
this.name = name;  
this.mailList = mailList;  
}
public void addMailToFolder(Mail mail)  
{
mailList.add(mail);  
}
public Boolean removeMailFromFolder(Long id)  
{
boolean flag=false;  
for(inti=0;i<mailList.size();i++)  
{
if(mailList.get(i).getId().equals(id))  
{
mailList.remove(i);  
flag=true;  
}
}
return flag;  
}
public void displayMails()  
{
if(mailList.size()==0)  
{
System.out.println("No mails to show");  
}
else  
{
System.out.println("Mails in "+name);  
System.out.printf("%-10s%-15s%-15s%-15s%-20s%-15s%-10s\n",  
"Id","From","To","Subject","Content","ReceivedDate","Size");  
for(Mail m:mailList)  
{
System.out.print(m);  
}
}
}
}
Page of  
Mail Folder - Requirement 3  
Requirement 3:  
In this requirement, you need to validate the email id. Also, you need to find whether  
the email is spam or not.  
a)Create a Class Main with the following static methods:  
Method Name  
Description  
Validate the email id based on t  
rules given below. Returns true  
if email id is valid else return fa  
static Boolean validateEmailId(String email)  
Checks for the spam domain  
name in the given email id.  
Returns true if the mail is spam  
else returns false  
static Boolean validateSpam(String email)  
b) While validating email id follow the below rules. The format of the email id is given  
below  
username@domain.TLD  
where, TLD - Top Level Domain  
1
2
. The email id should start only with alphabets(either uppercase or lowercase).  
. The email username can contain alphabets(either uppercase or lowercase), numbers  
and the special characters ( . and _ ).  
3
. The email username should not contain any special characters other than" . " and " _  
"
.
4
5
6
7
. After the username special character @ should present.  
. The email domain should contain only alphabets(either uppercase or lowercase).  
. After email domain, a value dot ( . ) should present.  
. The email Top Level Domain should contain only alphabets(both uppercase and  
lowercase) and it should have only 2 to 6 characters.  
Example: alpha_Beta.01@google.com is a valid email id.  
Since the username contain only alphabets, numbers and a special character ( _ and .  
)
, then the @ symbol is present. The domain name should contain only alphabets and  
the symbol dot( . ) and the Top Level Domain have only 3 characters.  
c) While checking for spam follow the below rules,  
If the domain name of the email id is one of the following then it is spam email id.  
advancedpdfconverter, passwordmaster, smartfixer, downloadavideo }  
{
Note: Print "Email is valid" if email is valid else print "Email is invalid". Print "Email is  
spam" if email is spam else print "Email is not spam".  
All the above print statements are present in the main method.  
Menu:  
1
2
.Validate Email  
.Check for Spam  
Sample Input and Output 1:  
1
2
.Validate Email  
.Check for Spam  
Enter your choice:  
1
Enter the email to be validated:  
alpha_Beta.02@mail.com  
Email is valid  
Sample Input and Output 2:  
1
2
.Validate Email  
.Check for Spam  
Enter your choice:  
1
Enter the email to be validated:  
0
alpf&sk@mail.in  
Email is invalid  
Sample Input and Output 3:  
1
2
.Validate Email  
.Check for Spam  
Enter your choice:  
2
Enter the email to be validated:  
jane@abc.in  
Email is not spam  
Sample Input and Output 4:  
1
2
.Validate Email  
.Check for Spam  
Enter your choice:  
2
Enter the email to be validated:  
jack@passwordmaster.com  
Email is spam  
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
public class Main {  
public static void main(String args[]) throws NumberFormatException, IOException {  
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));  
System.out.println("1.Validate Email\n2.Check for Spam\nEnter your choice:");  
Integer choice=Integer.parseInt(br.readLine());  
if(choice==1) {  
System.out.println("Enter the email to be validated:");  
/
/write your code here  
String email=br.readLine();  
if(validateEmailId(email))  
{
System.out.println("Email is valid");  
}
else  
System.out.println("Email is invalid");  
}
if(choice==2) {  
System.out.println("Enter the email to be validated:");  
/
/write your code here  
String email=br.readLine();  
if(validateSpam(email))  
{
System.out.println("Email is spam");  
}
else  
System.out.println("Email is not spam");  
}
}
public static Boolean validateEmailId(String email) {  
/
/write your code here  
if(!(Character.isAlphabetic(email.charAt(0))))  
{
return false;  
}
String s1[]=email.split("@");  
String username=s1[0];  
for(inti=0;i<username.length();i++)  
{
if(!(Character.isAlphabetic(username.charAt(i))||username.contains(".")||username.contains("  
_")))  
{
return false;  
}
}
if(s1.length==1)  
{
return false;  
}
String s2[]=s1[1].split("\\.");  
String domain=s2[0];  
for(inti=0;i<domain.length();i++)  
{
if(!(Character.isAlphabetic(domain.charAt(i))))  
{
return false;  
}
}
if(s2.length==1)  
{
return false;  
}
String tld=s2[1];  
for(inti=0;i<tld.length();i++)  
{
if(!(Character.isAlphabetic(tld.charAt(i))&&tld.length()>=2&&tld.length()<=6))  
{
return false;  
}
}
return true;  
}
public static Boolean validateSpam(String email) {  
/
/write your code here  
String s1[]=email.split("@");  
String s2[]=s1[1].split("\\.");  
String domain=s2[0];  
if(!(domain.equals("advancedpdfconverter")||domain.equals("passwordmaster")||domain.equ  
als("smartfixer")||domain.equals("downloadavideo")))  
{
}
return false;  
return true;  
}
}
Page of  
Mail Folder - Requirement 4  
Requirement 4:  
In this requirement develop a feature in which you can search a List of Mails by to address,  
receivedDate and size.  
a) Create a Class Mail with the following attributes:  
Member Field Name  
Type  
id  
Long  
to  
String  
from  
String  
subject  
content  
receivedDate  
size  
String  
String  
java.util.Date  
Double  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add a default  
constructor and a parameterized constructor to take in all attributes in the given order: Mail(Long  
id, String to, String from, String subject, String content,DatereceivedDate,Double size)  
b) Create a class MailBOwith the following methods,  
Method Name  
Description  
This method accepts a list of mails and to address  
arguments and returns a list of mails that matches  
with given to address.  
public List<Mail>findMail(List<Mail>mailList,String to)  
This method accepts a list of mails and received d  
as arguments and returns a list of mails that were  
received on the given specified date.  
public  
List<Mail>findMail(List<Mail>mailList,DatereceivedDate)  
This method accepts a list of mails and size as  
arguments, then find all the mails with the given s  
from the mail list and return the list of mails with  
specified size.  
public List<Mail>findMail(List<Mail>mailList,Double size)  
The mail details should be given as a comma-separated value in the below order,  
id,to,from, subject, content, receivedDate,size  
When the “mail” object is printed, it should display the following details  
Print format:  
System.out.format("%-10s %-20s %-25s %-20s %-20s %-15s %s\n",  
"
Id","To","From","Subject","Content","ReceivedDate","Size");  
Note: The mail lists are displayed in the main method.  
If any other choice is selected, display "Invalid Choice"  
Display one digit after the decimal point for Double Datatype.  
Sample Input and Output 1:  
Enter the number of Mails:  
4
1
2
1
1
1
2
001,meyyappan@gmail.com,satish@gmail.com,Master Copy,Attached doc,05-05-  
017,10.0  
010,morsh@gmail.com,meyyappan@hotmail.com,TaskList,Attached doc,25-01-2018,15.1  
016,sami@rediff.com,morsh@gmail.com,Remainder Mail,Today'schedule,24-01-2018,5.4  
020,praveens@yahoo.com,roshan@gmail.com,Remainder Mail,Today'schedule,24-01-  
018,5.4  
Enter a search type:  
1
2
3
1
.By To Address  
.By Received Date  
.By Size  
Enter the To Address:  
praveens@yahoo.com  
Received  
Date  
Id To  
From  
Subject  
Content  
Size  
Remiander  
Mail  
Today's  
schedule  
1
020 praveens@yahoo.com roshan@gmail.com  
24-01-2018 5.4  
Sample Input and Output 2:  
Enter the number of Mails:  
4
1
2
1
1
1
2
001,meyyappan@gmail.com,satish@gmail.com,Master Copy,Attached doc,05-05-  
017,10.0  
010,morsh@gmail.com,meyyappan@hotmail.com,TaskList,Attached doc,25-01-2018,15.1  
016,sami@rediff.com,morsh@gmail.com,Remainder Mail,Today'schedule,24-01-2018,5.4  
020,praveens@yahoo.com,roshan@gmail.com,Remainder Mail,Today'schedule,24-01-  
018,5.4  
Enter a search type:  
.By To Address  
1
2
3
2
.By Received Date  
.By Size  
Enter the Received Date:  
2
4-01-2018  
Received  
Date  
Id To  
From  
Subject  
Content  
Size  
Remainder  
Mail  
Remainder  
Mail  
Today's  
schedule  
Today's  
schedule  
1
1
016 sami@rediff.com  
morsh@gmail.com  
24-01-2018 5.4  
24-01-2018 5.4  
020 praveens@yahoo.com roshan@gmail.com  
Sample Input and Output 3:  
Enter the number of Mails:  
4
1
2
1
1
1
2
001,meyyappan@gmail.com,satish@gmail.com,Master Copy,Attached doc,05-05-  
017,10.0  
010,morsh@gmail.com,meyyappan@hotmail.com,TaskList,Attached doc,25-01-2018,15.1  
016,sami@rediff.com,morsh@gmail.com,Remainder Mail,Today'schedule,24-01-2018,5.4  
020,praveens@yahoo.com,roshan@gmail.com,Remainder Mail,Today'schedule,24-01-  
018,5.4  
Enter a search type:  
1
2
3
3
.By To Address  
.By Received Date  
.By Size  
Enter the Size:  
5
.4  
Received  
Date  
Id To  
From  
Subject  
Content  
Size  
Remainder  
Mail  
Remainder  
Mail  
Today's  
schedule  
Today's  
schedule  
1
1
016 sami@rediff.com  
morsh@gmail.com  
24-01-2018 5.4  
24-01-2018 5.4  
020 praveens@yahoo.com roshan@gmail.com  
Sample Input and Output 4:  
Enter the number of Mails:  
4
1
2
1
1
1
2
001,meyyappan@gmail.com,satish@gmail.com,Master Copy,Attached doc,05-05-  
017,10.0  
010,morsh@gmail.com,meyyappan@hotmail.com,TaskList,Attached doc,25-01-2018,15.1  
016,sami@rediff.com,morsh@gmail.com,Remainder Mail,Today'schedule,24-01-2018,5.4  
020,praveens@yahoo.com,roshan@gmail.com,Remainder Mail,Today'schedule,24-01-  
018,5.4  
Enter a search type:  
1
2
3
4
.By To Address  
.By Received Date  
.By Size  
Invalid choice  
importjava.util.Date;  
publicclass Mail {  
//Your code goes here...  
private Long id;  
private String to;  
private String from;  
private String subject;  
private String content;  
privatejava.util.DatereceivedDate;  
private Double size;  
public Long getId() {  
returnid;  
}
publicvoidsetId(Long id) {  
this.id = id;  
}
public String getTo() {  
returnto;  
}
publicvoidsetTo(String to) {  
this.to = to;  
}
public String getFrom() {  
returnfrom;  
}
publicvoidsetFrom(String from) {  
this.from = from;  
}
public String getSubject() {  
returnsubject;  
}
publicvoidsetSubject(String subject) {  
this.subject = subject;  
}
public String getContent() {  
returncontent;  
}
publicvoidsetContent(String content) {  
this.content = content;  
}
publicjava.util.DategetReceivedDate() {  
returnreceivedDate;  
}
publicvoidsetReceivedDate(java.util.DatereceivedDate) {  
this.receivedDate = receivedDate;  
}
public Double getSize() {  
returnsize;  
}
publicvoidsetSize(Double size) {  
this.size = size;  
}
publicMail(Long id, String to, String from, String subject,  
String content, Date receivedDate, Double size) {  
super();  
this.id = id;  
this.to = to;  
this.from = from;  
this.subject = subject;  
this.content = content;  
this.receivedDate = receivedDate;  
this.size = size;  
}
publicMail() {  
super();  
}
}
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
public class MailBO {  
public List<Mail>findMail(List<Mail>mailList,String to){  
/
/Your code goes here...  
List<Mail>l1=new ArrayList<>();  
for(Mail m1:mailList)  
{
if(m1.getTo().equals(to))  
l1.add(m1);  
}
return l1;  
}
public List<Mail>findMail(List<Mail>mailList,DatereceivedDate){  
/
/Your code goes here...  
List<Mail>l2=new ArrayList<>();  
for(Mail m2:mailList)  
{
if(m2.getReceivedDate().equals(receivedDate))  
{
l2.add(m2);  
}
}
return l2;  
}
public List<Mail>findMail(List<Mail>mailList,Double size){  
/Your code goes here...  
/
List<Mail>l3=new ArrayList<>();  
for(Mail m3:mailList)  
{
if(m3.getSize().equals(size))  
{
l3.add(m3);  
}
}
return l3;  
}
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
public class Main {  
public static void main(String[] args) throws NumberFormatException, IOException, ParseException {  
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));  
/
/Your code goes here...  
SimpleDateFormatsdf=new SimpleDateFormat("dd-MM-yyyy");  
Mail m=new Mail();  
MailBOmo=new MailBO();  
List<Mail>mailList=new ArrayList<>();  
System.out.println("Enter the number of Mails:");  
/
/Your code goes here...  
int n=Integer.parseInt(br.readLine());  
for(inti=0;i<n;i++)  
{
String s=br.readLine();  
String s1[]=s.split(",");  
m=new  
Mail(Long.parseLong(s1[0]),s1[1],s1[2],s1[3],s1[4],sdf.parse(s1[5]),Double.parseDouble(s1[6]));  
mailList.add(m);  
}
System.out.println("Enter a search type:\n1.By To Address\n2.By Received Date\n3.By  
Size");  
/
/Your code goes here...  
int choice=Integer.parseInt(br.readLine());  
switch(choice)  
{
case 1:  
System.out.println("Enter the To Address:");  
String add=br.readLine();  
List<Mail> l1=mo.findMail(mailList, add);  
System.out.format("%-10s %-20s %-25s %-20s %-20s %-15s %s\n",  
Id","To","From","Subject","Content","ReceivedDate","Size");  
"
for(Mail m1:l1)  
{
System.out.format("%-10s %-20s %-25s %-20s %-20s %-15s %s\n",  
m1.getId(),m1.getTo(),m1.getFrom(),m1.getSubject(),m1.getContent(),sdf.format(m1.getReceivedDate()  
),m1.getSize());  
}
break;  
case 2:  
System.out.println("Enter the Received Date:");  
String date=br.readLine();  
Date da=sdf.parse(date);  
List<Mail>l2=mo.findMail(mailList, da);  
System.out.format("%-10s %-20s %-25s %-20s %-20s %-15s %s\n",  
"Id","To","From","Subject","Content","ReceivedDate","Size");  
for(Mail m2:l2)  
{
System.out.format("%-10s %-20s %-25s %-20s %-20s %-15s %s\n",  
m2.getId(),m2.getTo(),m2.getFrom(),m2.getSubject(),m2.getContent(),sdf.format(m2.getReceivedDate()  
,m2.getSize());  
)
}
break;  
case 3:  
System.out.println("Enter the Size:");  
Double siz=Double.parseDouble(br.readLine());  
List<Mail>l3=mo.findMail(mailList, siz);  
System.out.format("%-10s %-20s %-25s %-20s %-20s %-15s %s\n",  
"Id","To","From","Subject","Content","ReceivedDate","Size");  
for(Mail m3:l3)  
{
System.out.format("%-10s %-20s %-25s %-20s %-20s %-15s %s\n",  
m3.getId(),m3.getTo(),m3.getFrom(),m3.getSubject(),m3.getContent(),sdf.format(m3.getReceivedDate()  
),m3.getSize());  
}
break;  
default:  
System.out.println("Invalid choice");  
break;  
}
}
}
Page of  
Mail Folder - Requirement 5  
Requirement 5:  
In this requirement, you need to sort the list of mails based on from address,  
receivedDate or size.  
a) Create a Class Mail with the following attributes:  
Member Field Name  
Type  
id  
Long  
from  
String  
to  
String  
subject  
content  
receivedDate  
size  
String  
String  
java.util.Date  
Double  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order: Mail(Long id, String from, String to, String subject, String content, Date  
receivedDate, Double size)  
b) Create the following static methods in the Mail class,  
Method Name  
Description  
static Mail  
This method accepts a String. The mail detail separated by commas is pass  
createMail(String detail) as the argument. Split the details and create a mail object and returns it.  
The mail details should be given as a comma-separated value in the below order,  
id,from,to,subject,content,receivedDate,size  
c) The Mail class should implement the Comparable interface which sorts the Mail list  
based on from address. While comparing, all the from address in the list are unique.  
d) Create a class DateComparator which implements Comparator interface and sort  
the Mail list based on receivedDate. While comparing, all the receivedDate attributes in  
the list are unique.  
e) Create a class SizeComparator which implements Comparator interface and sort the  
Mail list based on the size. While comparing, all the size attributes in the list are unique.  
Get the number of Mail and mail details and create a mail list. Sort the mail according to  
the given option and display the list.  
When the “mail” object is printed, it should display the following details  
Print format:  
System.out.format("%-15s %-15s %-15s %-20s %-20s %-15s %s\n",  
"
Id","From","To","Subject","Content","Receiveddate","Size");  
Display one digit after decimal point for Double datatype.  
Sample Input and Output 1:  
Enter the number of mails:  
4
1
2
3
2
4
,raj@abc.in,bala@abc.in,Freshers' list,PFA the Freshers db,05-01-2018,256  
,amir@abc.in,chris@abc.in,M.O.M,PFA the M.O.M,29-01-2018,678  
,abdul@abc.in,antony@abc.in,project requirement,PFA the requirements,20-01-  
018,1658  
,karim@abc.in,krishna@abc.in,Accounts,PFA the accounts,27-01-2018,2048  
Enter a type to sort:  
1
2
3
1
.Sort by from address  
.Sort by date received  
.Sort by size  
Id  
From  
To  
Subject  
Received date Size  
abdul@abc.in antony@abc.in project requirement PFA the requirements  
0-01-2018 1658.0  
amir@abc.in chris@abc.in  
9-01-2018 678.0  
karim@abc.in krishna@abc.in Accounts  
27-01-2018 2048.0  
bala@abc.in Freshers' list  
05-01-2018 256.0  
Content  
3
2
2
M.O.M  
PFA the M.O.M  
2
4
PFA the  
PFA the  
accounts  
1
Freshersdb  
raj@abc.in  
Sample Input and Output 2:  
Enter the number of mails:  
4
1
2
3
2
4
,raj@abc.in,bala@abc.in,Freshers' list,PFA the Freshers db,05-01-2018,256  
,amir@abc.in,chris@abc.in,M.O.M,PFA the M.O.M,29-01-2018,678  
,abdul@abc.in,antony@abc.in,project requirement,PFA the requirements,20-01-  
018,1658  
,karim@abc.in,krishna@abc.in,Accounts,PFA the accounts,27-01-2018,2048  
Enter a type to sort:  
1
2
3
.Sort by from address  
.Sort by date received  
.Sort by size  
2
Id  
From  
To  
Subject  
Content  
Received date Size  
1
raj@abc.in  
bala@abc.in  
Freshers' list  
PFA the  
Freshersdb  
05-01-2018 256.0  
3
2
4
abdul@abc.in antony@abc.in project requirement PFA the requirements  
0-01-2018  
1658.0  
karim@abc.in krishna@abc.in Accounts  
PFA the  
PFA the M.O.M  
accounts  
amir@abc.in  
9-01-2018  
27-01-2018  
chris@abc.in  
678.0  
2048.0  
2
M.O.M  
2
Sample Input and Output 3:  
Enter the number of mails:  
4
1
2
3
2
4
,raj@abc.in,bala@abc.in,Freshers' list,PFA the Freshers db,05-01-2018,256  
,amir@abc.in,chris@abc.in,M.O.M,PFA the M.O.M,29-01-2018,678  
,abdul@abc.in,antony@abc.in,project requirement,PFA the requirements,20-01-  
018,1658  
,karim@abc.in,krishna@abc.in,Accounts,PFA the accounts,27-01-2018,248  
Enter a type to sort:  
1
2
3
3
.Sort by from address  
.Sort by date received  
.Sort by size  
Id  
Content  
karim@abc.in krishna@abc.in Accounts  
From  
To  
Subject  
Received date Size  
4
PFA the  
PFA the  
accounts  
27-01-2018  
248.0  
1
raj@abc.in  
bala@abc.in  
256.0  
chris@abc.in  
Freshers' list  
M.O.M  
Freshersdb  
2
05-01-2018  
amir@abc.in PFA the M.O.M  
9-01-2018  
abdul@abc.in antony@abc.in project requirement PFA the requirements  
0-01-2018 1658.0  
2
678.0  
3
2
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Date;  
public class Mail implements Comparable<Mail>{  
/Your code here  
private Long id;  
/
private String from;  
private String to;  
private String subject;  
private String content;  
private java.util.DatereceivedDate;  
private Double size;  
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getFrom() {  
return from;  
}
public void setFrom(String from) {  
this.from = from;  
}
public String getTo() {  
return to;  
}
public void setTo(String to) {  
this.to = to;  
}
public String getSubject() {  
return subject;  
}
public void setSubject(String subject) {  
this.subject = subject;  
}
public String getContent() {  
return content;  
}
public void setContent(String content) {  
this.content = content;  
}
public java.util.DategetReceivedDate() {  
return receivedDate;  
}
public void setReceivedDate(java.util.DatereceivedDate) {  
this.receivedDate = receivedDate;  
}
public Double getSize() {  
return size;  
}
public void setSize(Double size) {  
this.size = size;  
}
public Mail(Long id, String from, String to, String subject,  
String content, Date receivedDate, Double size) {  
super();  
this.id = id;  
this.from = from;  
this.to = to;  
this.subject = subject;  
this.content = content;  
this.receivedDate = receivedDate;  
this.size = size;  
}
public Mail() {  
super();  
}
public static Mail createMail(String detail) throws NumberFormatException, ParseException{  
/Your code here  
/
SimpleDateFormatsdf=new SimpleDateFormat("dd-MM-yyyy");  
String s[]=detail.split(",");  
Mail m=new  
Mail(Long.parseLong(s[0]),s[1],s[2],s[3],s[4],sdf.parse(s[5]),Double.parseDouble(s[6]));  
return m;  
}
@Override  
public intcompareTo(Mail m1) {  
/
/ TODO Auto-generated method stub  
return this.from.compareTo(m1.getFrom());  
}
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Collections;  
import java.util.List;  
public class Main {  
public static void main(String args[]) throws NumberFormatException, IOException, ParseException{  
BufferedReaderbr = new BufferedReader(new InputStreamReader(System.in));  
/
/Your code here  
List<Mail>list=new ArrayList<>();  
SimpleDateFormatsdf=new SimpleDateFormat("dd-MM-yyyy");  
/
/Mail m=new Mail();  
System.out.println("Enter the number of mails:");  
/Your code here  
/
int n=Integer.parseInt(br.readLine());  
for(inti=0;i<n;i++)  
{
String detail=br.readLine();  
list.add(Mail.createMail(detail));  
}
System.out.println("Enter a type to sort:\n1.Sort by from address\n2.Sort by date  
received\n3.Sort by size");  
/
/Your code here  
int choice=Integer.parseInt(br.readLine());  
switch(choice)  
{
case 1:  
Collections.sort(list);  
System.out.format("%-15s %-15s %-15s %-20s %-20s %-15s %s\n",  
"Id","From","To","Subject","Content","Receiveddate","Size");  
for(Mail m1:list)  
{
System.out.format("%-15s %-15s %-15s %-20s %-20s %-15s %s\n",  
m1.getId(),m1.getFrom(),m1.getTo(),m1.getSubject(),m1.getContent(),sdf.format(m1.getReceivedDate()  
,m1.getSize());  
)
}
break;  
case 2:  
Collections.sort(list,newDateComparator());  
System.out.format("%-15s %-15s %-15s %-20s %-20s %-15s %s\n",  
"Id","From","To","Subject","Content","Receiveddate","Size");  
for(Mail m2:list)  
{
System.out.format("%-15s %-15s %-15s %-20s %-20s %-15s %s\n",  
m2.getId(),m2.getFrom(),m2.getTo(),m2.getSubject(),m2.getContent(),sdf.format(m2.getReceivedDate()  
,m2.getSize());  
)
}
break;  
case 3:  
Collections.sort(list,newSizeComparator());  
System.out.format("%-15s %-15s %-15s %-20s %-20s %-15s %s\n",  
"Id","From","To","Subject","Content","Receiveddate","Size");  
for(Mail m3:list)  
{
System.out.format("%-15s %-15s %-15s %-20s %-20s %-15s %s\n",  
m3.getId(),m3.getFrom(),m3.getTo(),m3.getSubject(),m3.getContent(),sdf.format(m3.getReceivedDate()  
),m3.getSize());  
}
break;  
}
}
}
importjava.util.Comparator;  
publicclassSizeComparatorimplements Comparator<Mail>{  
@
Override  
publicintcompare(Mail s1, Mail s2) {  
/ TODO Auto-generated method stub  
/
if(s1.getSize()>s2.getSize())  
return 1;  
elseif(s1.getSize()<s2.getSize())  
return -1;  
else  
return 0;  
}
//Your code here  
}
importjava.util.Comparator;  
publicclassDateComparatorimplements Comparator<Mail>{  
@
Override  
publicintcompare(Mail d1, Mail d2) {  
/ TODO Auto-generated method stub  
returnd1.getReceivedDate().compareTo(d2.getReceivedDate());  
/
}
//Your code here  
}
Page of  
Mail Folder - Requirement 6  
Requirement 6:  
In this requirement, given a list of mails you need to find the number of mails received each day  
using Map.  
a) Create a Class Mail with the following attributes:  
Member Field Name  
Type  
id  
String  
from  
String  
to  
String  
subject  
content  
receivedDate  
size  
String  
String  
java.util.Date  
Double  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters. Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order: Mail(Long id, String from, String to, String subject, String content, Date  
receivedDate, Double size)  
b) Create the following static methods in the Mail class,  
Method Name  
Description  
static  
This method accepts a list of Mail as arguments and retu  
a TreeMap with the receivedDate as key and number of  
mails received on that date as value and returns the map.  
Map<Date,Integer>calculateDateCount(List<Mail>  
list)  
In the TreeMap have the receivedDate as key and Count the number of mails received on the  
date and keep the number of mails as value. Print the value sorted by Date.  
The mail details should be given as a comma separated value in the below order,  
id,from,to,subject,content,receivedDate,size  
Print format:  
System.out.format("%-15s %s\n","Date","Count");  
Sample Input and Output 1:  
Enter the number of mails:  
5
2
2
5
5
18,krish@abc.com,ram@abc.com,Freshers' list,PFA the Freshers db,05-10-  
016,1256  
69,ani@abc.com,gautham@abc.com,M.O.M,PFA the M.O.M,05-10-2016,1896  
38,ram12@abc.com,ravi@abc.com,project requirement,PFA the  
requirements,20-11-2011,1058  
1
9
02,ganesh@abc.com,chris@abc.com,Accounts,PFA the accounts,20-11-2011,48  
97,sam@abc.com,rahim@abc.com,Appraisal,PFA appraisal db,27-01-2007,2148  
Date  
Count  
2
2
0
7-01-2007  
0-11-2011  
5-10-2016  
1
2
2
import java.util.Date;  
import java.util.List;  
import java.util.Map;  
import java.util.TreeMap;  
public class Mail{  
/Your code here  
private Long id;  
/
private String from,to,subject,content;  
private java.util.DatereceivedDate;  
private Double size;  
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getFrom() {  
return from;  
}
public void setFrom(String from) {  
this.from = from;  
}
public String getTo() {  
return to;  
}
public void setTo(String to) {  
this.to = to;  
}
public String getSubject() {  
return subject;  
}
public void setSubject(String subject) {  
this.subject = subject;  
}
public String getContent() {  
return content;  
}
public void setContent(String content) {  
this.content = content;  
}
public java.util.DategetReceivedDate() {  
return receivedDate;  
}
public void setReceivedDate(java.util.DatereceivedDate) {  
this.receivedDate = receivedDate;  
}
public Double getSize() {  
return size;  
}
public void setSize(Double size) {  
this.size = size;  
}
public Mail(Long id, String from, String to, String subject,  
String content, Date receivedDate, Double size) {  
super();  
this.id = id;  
this.from = from;  
this.to = to;  
this.subject = subject;  
this.content = content;  
this.receivedDate = receivedDate;  
this.size = size;  
}
public Mail() {  
super();  
}
public static Map<Date,Integer>calculateDateCount(List<Mail> list){  
/
/Your code here  
Map<Date,Integer>cmap=new TreeMap<>();  
int q=1;  
for(Mail m:list)  
{
if(cmap.containsKey(m.getReceivedDate()))  
{
q=cmap.get(m.getReceivedDate());  
q++;  
cmap.put(m.getReceivedDate(),q);  
}
else  
cmap.put(m.getReceivedDate(), 1);  
}
return cmap;  
}
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
import java.util.Map;  
public class Main {  
public static void main(String[] args) throws NumberFormatException, IOException,  
ParseException{  
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));  
/Your code here  
/
List<Mail>list=new ArrayList<>();  
Mail m=new Mail();  
SimpleDateFormatsdf=new SimpleDateFormat("dd-MM-yyyy");  
System.out.println("Enter the number of mails:");  
/
/Your code here  
int n=Integer.parseInt(br.readLine());  
for(inti=0;i<n;i++)  
{
String s=br.readLine();  
String s1[]=s.split(",");  
m=new  
Mail(Long.parseLong(s1[0]),s1[1],s1[2],s1[3],s1[4],sdf.parse(s1[5]),Double.parseDouble(s1[6]));  
list.add(m);  
}
Map<Date,Integer>map=Mail.calculateDateCount(list);  
System.out.format("%-15s %s\n","Date","Count");  
for(Date j:map.keySet())  
{
System.out.format("%-15s %d\n",sdf.format(j),map.get(j));  
}
}
}
Page of  
Team - Requirement 1  
It's the month of January of a New Year, and its time for IPL auction. Watching the  
auction taking place you find it difficult to keep track of the players each team has  
picked. Being a techie you decide to create a small application which would help people  
to keep track of the players and team details. There are two major domains Player and  
Team  
Requirement 1:  
Let’s start off by creating two Player objects and check whether they are equal.  
1
. Create a Player Class with the following attributes:  
Member Field Name  
name  
Type  
String  
dateOfBirth  
skill  
java.util.Date  
String  
numberOfMatches  
runs  
Integer  
Integer  
Integer  
String  
wickets  
nationality  
powerRating  
Double  
2
3
4
. Mark all the attributes as private  
. Create / Generate appropriate Getters & Setters  
. Add a default constructor and a parameterized constructor to take in all attributes  
in the given order:  
Player(String name , Date dateOfBirth , String skill , Integer  
numberOfMatches , Integer runs , Integer wickets , String nationality ,  
Double powerRating)  
5
. When the “player” object is printed, it should display the following details:  
[
Override the toString method]  
Print format:  
Name:"name"  
Date of Birth:"dateOfBirth"  
Skill:"skill"  
Number of Matches:"numberOfMatches"  
Runs:"runs"  
Wickets:"wickets"  
Nationality:"nationality"  
PowerRating:"powerRating"  
6
. Two players are considered same if they have the same name, skill, and  
nationality. Implement the logic in the appropriate function. (Case  Insensitive)  
[
Override the equals method]  
The input format consists of mail details separated by comma in the below order,  
name,dateOfBirth,skill,numberOfMatches,runs,wickets,nationality,powerR  
ating)  
(
The Input to your program would be details of two players, you need to display their  
details as given in "5th point(refer above)" and compare the two players and display if  
the Players are same or different.  
Note: There is an empty line between display statements. Print the empty lines in the  
main function.  
Display one digit after the decimal point for Double datatype.  
Sample INPUT & OUTPUT 1:  
Enter player 1 detail:  
MSD,07-07-1981,WK&BAT,300,10000,2,Indian,4.9  
Enter player 2 detail:  
MSD,07-07-1981,WK&BAT,300,10000,2,Indian,4.9  
Player 1:  
Name:MSD  
Date of Birth:07-07-1981  
Skill:WK&BAT  
Number of Matches:300  
Runs:10000  
Wickets:2  
Nationality:Indian  
Power Rating:4.9  
Player 2:  
Name:MSD  
Date of Birth:07-07-1981  
Skill:WK&BAT  
Number of Matches:300  
Runs:10000  
Wickets:2  
Nationality:Indian  
Power Rating:4.9  
Player 1 is same as Player 2  
Sample INPUT & OUTPUT 2:  
Enter player 1 detail:  
MSD,07-07-1981,WK&BAT,300,10000,2,Indian,4.9  
Enter player 2 detail:  
ABD,17-02-1984,WK&BAT,300,10000,3,South African,4.9  
Player 1:  
Name:MSD  
Date of Birth:07-07-1981  
Skill:WK&BAT  
Number of Matches:300  
Runs:10000  
Wickets:2  
Nationality:Indian  
Power Rating:4.9  
Player 2:  
Name:ABD  
Date of Birth:17-02-1984  
Skill:WK&BAT  
Number of Matches:300  
Runs:10000  
Wickets:3  
Nationality:South African  
Power Rating:4.9  
Player 1 and Player 2 are different  
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
public class Main {  
public static void main(String []args) throws IOException, NumberFormatException,  
ParseException{  
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));  
/
/Your code goes here...  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
Player p[]=new Player[2];  
System.out.println("Enter player 1 detail:");  
/
/Your code goes here...  
String s=reader.readLine();  
String s1[]=s.split(",");  
p[0]=new  
Player(s1[0],sdf.parse(s1[1]),s1[2],Integer.parseInt(s1[3]),Integer.parseInt(s1[4]),Integer.parseInt(s1[5]),  
s1[6],Double.parseDouble(s1[7]));  
System.out.println("Enter player 2 detail:");  
/
/Your code goes here...  
String p1=reader.readLine();  
String s2[]=p1.split(",");  
p[1]=new  
Player(s2[0],sdf.parse(s2[1]),s2[2],Integer.parseInt(s2[3]),Integer.parseInt(s2[4]),Integer.parseInt(s2[5]),  
s2[6],Double.parseDouble(s2[7]));  
for(int i=0;i<2;i++)  
{
}
System.out.println("Player "+(i+1)+":");  
System.out.println(p[i]);  
if(p[0].equals(p[1]))  
{
System.out.println("Player 1 is same as Player 2 ");  
}
else  
System.out.println("Player 1 and Player 2 are different");  
}
}
import java.text.SimpleDateFormat;  
import java.util.Date;  
public class Player {  
/
/your code goes here...  
private String name;  
private java.util.Date dateOfBirth;  
private String skill;  
private Integer numberOfMatches;  
private Integer runs;  
private Integer wickets;  
private String nationality;  
private Double powerRating;  
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public java.util.Date getDateOfBirth() {  
return dateOfBirth;  
}
public void setDateOfBirth(java.util.Date dateOfBirth) {  
this.dateOfBirth = dateOfBirth;  
}
public String getSkill() {  
return skill;  
}
public void setSkill(String skill) {  
this.skill = skill;  
}
public Integer getNumberOfMatches() {  
return numberOfMatches;  
}
public void setNumberOfMatches(Integer numberOfMatches) {  
this.numberOfMatches = numberOfMatches;  
}
public Integer getRuns() {  
return runs;  
}
public void setRuns(Integer runs) {  
this.runs = runs;  
}
public Integer getWickets() {  
return wickets;  
}
public void setWickets(Integer wickets) {  
this.wickets = wickets;  
}
public String getNationality() {  
return nationality;  
}
public void setNationality(String nationality) {  
this.nationality = nationality;  
}
public Double getPowerRating() {  
return powerRating;  
}
public void setPowerRating(Double powerRating) {  
this.powerRating = powerRating;  
}
public Player(String name, Date dateOfBirth, String skill,  
Integer numberOfMatches, Integer runs, Integer wickets,  
String nationality, Double powerRating) {  
super();  
this.name = name;  
this.dateOfBirth = dateOfBirth;  
this.skill = skill;  
this.numberOfMatches = numberOfMatches;  
this.runs = runs;  
this.wickets = wickets;  
this.nationality = nationality;  
this.powerRating = powerRating;  
}
public Player() {  
super();  
}
@
Override  
public int hashCode() {  
final int prime = 31;  
int result = 1;  
result = prime * result + ((name == null) ? 0 : name.hashCode());  
result = prime * result  
+
((nationality == null) ? 0 : nationality.hashCode());  
result = prime * result + ((skill == null) ? 0 : skill.hashCode());  
return result;  
}
@Override  
public boolean equals(Object obj) {  
if (this == obj)  
return true;  
if (obj == null)  
return false;  
if (getClass() != obj.getClass())  
return false;  
Player other = (Player) obj;  
if (name == null) {  
if (other.name != null)  
return false;  
}
else if (!name.equals(other.name))  
return false;  
if (nationality == null) {  
if (other.nationality != null)  
return false;  
else if (!nationality.equals(other.nationality))  
return false;  
}
if (skill == null) {  
if (other.skill != null)  
return false;  
}
else if (!skill.equals(other.skill))  
return false;  
return true;  
}
@Override  
public String toString() {  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
return "Name:"+name+"\nDate of  
Birth:"+sdf.format(dateOfBirth)+"\nSkill:"+skill+"\nNumber of  
Matches:"+numberOfMatches+"\nRuns:"+runs+"\nWickets:"+wickets+"\nNationality:"+nationality+"\nP  
ower Rating:"+powerRating;  
}
}
Page of  
Team - Requirement 2  
Requirement 2:  
In this requirement, we are gonna start creating a team and add players to it. Start with  
creating a team and use menu-driven approach to add, remove, display details of the  
player in the team.  
a)Create a Class Player with the following attributes:  
Member Field Name  
name  
Type  
String  
dateOfBirth  
skill  
java.util.Date  
String  
numberOfMatches  
runs  
Integer  
Integer  
Integer  
String  
wickets  
nationality  
powerRating  
Double  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order: public Player(String name, Date dateOfBirth, String skill, Integer  
numberOfMatches, Integer runs, Integer wickets, String nationality, Double  
powerRating).  
b)Create a Class Team with the following attributes:  
Member Field Name  
name  
Type  
String  
playerList  
List<Player>  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order: public Team(String name, List<Player> playerList). In constructor pass  
the playerList value as an empty list. Only one team will be present at a time.  
c) Create the following static method in Player class,  
Method Name  
Description  
public static Player  
This method accepts a String which contains player details separated  
createPlayer(String detail)  
commas. Split the details and create a player object from the details a  
it.  
The player details should be given as a comma-separated value in the below order,  
name,dateOfBirth,skill,numberOfMatches,runs,wickets,nationality,powerRating  
d) Create the following methods in Team class,  
Method Name  
Description  
public void addPlayerToTeam(Player  
player)  
This method accepts a Player object and add the player to t  
list of the current team.  
This method will get the name of the player and delete the p  
the specified name from the current team.  
If a player with the given name found, delete the player and  
true. If a player with the name is not found return false.  
The players name are unique.  
public Boolean  
removePlayerFromTeam(String name)  
This method will display the player list in the current team.  
If the player list is empty display "No players to show", els  
display "Players in [team name]" and display all the player d  
the specified format. Where [team name] specifies the name  
team.  
public void displayPlayers()  
After deletion, if true is returned print "Player successfully deleted", else print "Player  
not found in the team". After adding a player to the team, print "Player successfully  
added".  
Note: The above print statements should be present in the main method.  
When the “player” object is printed, it should display the following format  
Print format:  
System.out.printf("%-15s%-15s%-10s%-15s%-10s%-10s%-15s%-10s\n",  
"
Name","Date of birth","Skill","No of  
matches","Runs","Wickets","Nationality","Rating"). Display 1 digit after decimal  
point in Double.  
Sample Input and Output:  
Enter the name of the Team:  
Royal Challengers Banglore  
1
2
3
4
.Add Player  
.Delete Player  
.Display Players  
.Exit  
Enter your choice:  
3
No players to show  
1
.Add Player  
2
3
4
.Delete Player  
.Display Players  
.Exit  
Enter your choice:  
1
Enter the details of player in CSV format:  
Virat Kohli,05-11-1988,Batsman,149,4418,4,India,4.7  
Player successfully added  
1
2
3
4
.Add Player  
.Delete Player  
.Display Players  
.Exit  
Enter your choice:  
1
Enter the details of player in CSV format:  
Ab de Villiers,7-02-1984,Batsman,129,3473,0,S Africa,4.7  
Player successfully added  
1
2
3
4
.Add Player  
.Delete Player  
.Display Players  
.Exit  
Enter your choice:  
1
Enter the details of player in CSV format:  
Bhuvneshwar,05-02-1990,Bowler,90,158,111,India,4.1  
Player successfully added  
1
2
3
4
.Add Player  
.Delete Player  
.Display Players  
.Exit  
Enter your choice:  
1
Enter the details of player in CSV format:  
Mitchell Stark,30-01-1990,Bowler,27,96,34,Australia,4.1  
Player successfully added  
1
2
3
4
.Add Player  
.Delete Player  
.Display Players  
.Exit  
Enter your choice:  
2
Enter the name of the player to be deleted:  
MS Dhoni  
Player not found in the team  
1
2
.Add Player  
.Delete Player  
3
4
.Display Players  
.Exit  
Enter your choice:  
2
Enter the name of the player to be deleted:  
Bhuvneshwar  
Player successfully deleted  
1
2
3
4
.Add Player  
.Delete Player  
.Display Players  
.Exit  
Enter your choice:  
3
Players in:Royal Challengers Banglore  
Name  
Date of birth Skill No of matches Runs  
Wickets Nationality Rating  
Virat Kohli 05-11-1988 Batsman 149  
Ab de Villiers 07-02-1984 Batsman 129  
Mitchell Stark 30-01-1990 Bowler 27  
4418  
3473  
96  
4
0
34  
India  
S Africa  
Australia  
4.7  
4.7  
4.1  
1
2
3
4
.Add Player  
.Delete Player  
.Display Players  
.Exit  
Enter your choice:  
4
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.util.ArrayList;  
import java.util.List;  
public class Main {  
public static void main(String args[]) throws NumberFormatException, IOException,  
ParseException {  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
System.out.println("Enter the name of the Team:");  
/
/
/List<Player> playerList=new ArrayList<>();  
/write your code here  
String name=br.readLine();  
Team t=new Team(name,new ArrayList<>());  
System.out.println("1.Add Player\n2.Delete Player\n3.Display Players\n4.Exit\nEnter  
your choice:");  
Integer choice=Integer.parseInt(br.readLine());  
while(choice>0&&choice<4) {  
if(choice==1) {  
System.out.println("Enter the details of player in CSV format:");  
/
/write your code here  
String details=br.readLine();  
t.addPlayerToTeam(Player.createPlayer(details));  
System.out.println("Player successfully added");  
}
else if(choice==2) {  
System.out.println("Enter the name of the player to be deleted:");  
/
/write your code here  
String name1=br.readLine();  
if(t.removePlayerFromTeam(name1))  
{
System.out.println("Player successfully deleted");  
}
else  
System.out.println("Player not found in the team");  
}
else if(choice==3) {  
/
/write your code here  
t.displayPlayers();  
}
else if(choice==4)  
{
System.exit(0);  
}
System.out.println("1.Add Player\n2.Delete Player\n3.Display  
Players\n4.Exit\nEnter your choice:");  
choice=Integer.parseInt(br.readLine());  
}
}
}
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Date;  
public class Player {  
/
/write your code here  
private String name;  
private java.util.Date dateOfBirth;  
private String skill;  
private Integer numberOfMatches;  
private Integer runs;  
private Integer wickets;  
private String nationality;  
private Double powerRating;  
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public java.util.Date getDateOfBirth() {  
return dateOfBirth;  
}
public void setDateOfBirth(java.util.Date dateOfBirth) {  
this.dateOfBirth = dateOfBirth;  
}
public String getSkill() {  
return skill;  
}
public void setSkill(String skill) {  
this.skill = skill;  
}
public Integer getNumberOfMatches() {  
return numberOfMatches;  
}
public void setNumberOfMatches(Integer numberOfMatches) {  
this.numberOfMatches = numberOfMatches;  
}
public Integer getRuns() {  
return runs;  
}
public void setRuns(Integer runs) {  
this.runs = runs;  
}
public Integer getWickets() {  
return wickets;  
}
public void setWickets(Integer wickets) {  
this.wickets = wickets;  
}
public String getNationality() {  
return nationality;  
}
public void setNationality(String nationality) {  
this.nationality = nationality;  
}
public Double getPowerRating() {  
return powerRating;  
}
public void setPowerRating(Double powerRating) {  
this.powerRating = powerRating;  
}
public Player(String name, Date dateOfBirth, String skill,  
Integer numberOfMatches, Integer runs, Integer wickets,  
String nationality, Double powerRating) {  
super();  
this.name = name;  
this.dateOfBirth = dateOfBirth;  
this.skill = skill;  
this.numberOfMatches = numberOfMatches;  
this.runs = runs;  
this.wickets = wickets;  
this.nationality = nationality;  
this.powerRating = powerRating;  
}
public Player() {  
super();  
}
public static Player createPlayer(String detail) throws NumberFormatException, ParseException {  
/
/write your code here  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
String s[]=detail.split(",");  
Player p=new  
Player(s[0],sdf.parse(s[1]),s[2],Integer.parseInt(s[3]),Integer.parseInt(s[4]),Integer.parseInt(s[5]),s[6],Do  
uble.parseDouble(s[7]));  
return p;  
}
}
import java.text.DecimalFormat;  
import java.text.SimpleDateFormat;  
import java.util.List;  
public class Team {  
/
/write your code here  
private String name;  
private List<Player> playerList;  
Player p=new Player();  
/
/DecimalFormat df=new DecimalFormat("0.0");  
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public List<Player> getPlayerList() {  
return playerList;  
}
public void setPlayerList(List<Player> playerList) {  
this.playerList = playerList;  
}
public Team(String name, List<Player> playerList) {  
super();  
this.name = name;  
this.playerList = playerList;  
}
public Team() {  
super();  
}
public void addPlayerToTeam(Player player) {  
/
/write your code here  
playerList.add(player);  
}
public Boolean removePlayerFromTeam(String name) {  
/
/write your code here  
for(Player p:playerList)  
{
if(p.getName().equals(name))  
{
playerList.remove(p);  
return true;  
}
}
return false;  
}
public void displayPlayers() {  
/write your code here  
/
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
if(playerList.size()==0)  
{
System.out.println("No players to show");  
}
else{  
System.out.println("Players in:"+name);  
System.out.printf("%-15s%-15s%-10s%-15s%-10s%-10s%-15s%-10s\n", "Name","Date of  
birth","Skill","No of matches","Runs","Wickets","Nationality","Rating");  
for(Player p:playerList)  
{
System.out.printf("%-15s%-15s%-10s%-15d%-10d%-10d%-15s%-10.1f\n",  
p.getName(),sdf.format(p.getDateOfBirth()),p.getSkill(),p.getNumberOfMatches(),p.getRuns(),p.getWick  
ets(),p.getNationality(),p.getPowerRating());  
}
}
}
}
Page of  
Team - Requirement 3  
Requirement 3:  
In this requirement develop a feature in which you can search a List of Players by nationality,  
dateOfBirth or powerRating.  
a) Create a Class Player with the following attributes:  
Member Field Name  
name  
Type  
String  
dateOfBirth  
skill  
java.util.Date  
String  
numberOfMatches  
runs  
Integer  
Integer  
Integer  
String  
wickets  
nationality  
powerRating  
Double  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add a default  
constructor and a parameterized constructor to take in all attributes in the given order:  
Player(String name, Date dateOfBirth, String skill, Integer numberOfMatches, Integer  
runs,Integer wickets,String nationality,Double powerRating)  
b) Create a class PlayerBO with the following methods,  
Method Name  
Description  
public List<Player>  
findPlayer(List<Player>  
playerList,String nationality)  
This method accepts a list of players and Nationality as arguments and  
returns a list of players that match with given Nationality.  
public List<Player>  
findPlayer(List<Player> playerList,Date  
dateOfBirth)  
This method accepts a list of players and date of birth as arguments an  
returns a list of players who were born on the given date.  
public List<Player>  
findPlayer(List<Player>  
playerList,Double powerRating)  
This method accepts a list of players and power rating as arguments, th  
find all the players with the given power rating from the player list and  
return the list of players with the specified power rating.  
The player details should be given as a comma-separated value in the below order,  
name,dateOfBirth,skill,numberOfMatches,runs,wickets,nationality,powerRating  
Get the number of player and the player details, build a player list and perform the search by  
nationality,dateOfBirth or powerRating.  
When the “player” object is printed, it should display the following details  
Print format:  
System.out.format("%-15s %-15s %-15s %-20s %-15s %-15s %-15s  
%s\n","Name","Date of Birth","Skill","Number of  
Wickets","Runs","Wickets","Nationality","Power Rating");  
Note: The player lists are displayed in the main method.  
If any other choice is selected, display "Invalid choice"  
Display one digit after the decimal point for Double Datatype.  
Sample Input and Output 1:  
Enter the number of Players:  
4
MSD,07-07-1981,WK&BAT,300,10000,2,Indian,4.9  
ABD,17-02-1984,WK&BAT,300,10000,3,South African,4.9  
SRaina,27-11-1986,BAT,100,5000,50,Indian,4.5  
Maxwell,14-10-1988,ALLROUNDER,200,4000,50,Australian,4.5  
Enter a search type:  
1
2
3
1
.By Nationality  
.By Date of Birth  
.By Power Rating  
Enter the Nationality:  
Australian  
Date of  
Name  
Number of  
Matches  
Power  
Rating  
Australian 4.5  
Skill  
Runs Wickets Nationality  
4000 50  
Birth  
Maxwell 14-10-1988 ALLROUNDER 200  
Sample Input and Output 2:  
Enter the number of Players:  
4
MSD,07-07-1981,WK&BAT,300,10000,2,Indian,4.9  
ABD,17-02-1984,WK&BAT,300,10000,3,South African,4.9  
SRaina,27-11-1986,BAT,100,5000,50,Indian,4.5  
Maxwell,14-10-1988,ALLROUNDER,200,4000,50,Australian,4.5  
Enter a search type:  
1
.By Nationality  
2
3
2
.By Date of Birth  
.By Power Rating  
Enter the Date of Birth:  
0
7-07-1981  
Date of  
Birth  
Number of  
Matches  
Power  
Rating  
4.9  
Name  
Skill  
Runs Wickets Nationality  
10000 2 Indian  
MSD 07-07-1981 WK&BAT 300  
Sample Input and Output 3:  
Enter the number of Players:  
4
MSD,07-07-1981,WK&BAT,300,10000,2,Indian,4.9  
ABD,17-02-1984,WK&BAT,300,10000,3,South African,4.9  
SRaina,27-11-1986,BAT,100,5000,50,Indian,4.5  
Maxwell,14-10-1988,ALLROUNDER,200,4000,50,Australian,4.2  
Enter a search type:  
1
2
3
3
.By Nationality  
.By Date of Birth  
.By Power Rating  
Enter the Power Rating:  
4
.5  
Name Date of Birth Skill Number of Matches Runs Wickets Nationality Power Rating  
SRaina 27-11-1986 BAT 100  
5000 50  
Indian  
4.5  
Sample Input and Output 4:  
Enter the number of Players:  
4
MSD,07-07-1981,WK&BAT,300,10000,2,Indian,4.9  
ABD,17-02-1984,WK&BAT,300,10000,3,South African,4.9  
SRaina,27-11-1986,BAT,100,5000,50,Indian,4.5  
Maxwell,14-10-1988,ALLROUNDER,200,4000,50,Australian,4.2  
Enter a search type:  
1
2
3
4
.By Nationality  
.By Date of Birth  
.By Power Rating  
Invalid choice  
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
public class Main {  
public static void main(String args[]) throws NumberFormatException, IOException,  
ParseException {  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
/
/Your code goes here...  
List<Player>playerList=new ArrayList<>();  
PlayerBO bo=new PlayerBO();  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
System.out.println("Enter the number of Players:");  
/
/Your code goes here...  
int n=Integer.parseInt(br.readLine());  
for(int i=0;i<n;i++)  
{
String detail=br.readLine();  
String s[]=detail.split(",");  
Player p=new  
Player(s[0],sdf.parse(s[1]),s[2],Integer.parseInt(s[3]),Integer.parseInt(s[4]),Integer.parseInt(s[5]),s[6],Do  
uble.parseDouble(s[7]));  
playerList.add(p);  
}
System.out.println("Enter a search type:\n1.By Nationality\n2.By Date of Birth\n3.By  
Power Rating");  
/
/Your code goes here...  
int choice=Integer.parseInt(br.readLine());  
switch(choice)  
{
case 1:  
System.out.println("Enter the Nationality:");  
String a=br.readLine();  
List<Player> pl=bo.findPlayer(playerList, a);  
System.out.format("%-15s %-15s %-15s %-20s %-15s %-15s %-15s  
%
s\n","Name","Date of Birth","Skill","Number of Wickets","Runs","Wickets","Nationality","Power  
Rating");  
for(Player p:pl)  
{
System.out.format("%-15s %-15s %-15s %-20d %-15d %-15d %-15s  
%
.1f\n",p.getName(),sdf.format(p.getDateOfBirth()),p.getSkill(),p.getNumberOfMatches(),p.getRuns(),p.  
getWickets(),p.getNationality(),p.getPowerRating());  
}
break;  
case 2:  
System.out.println("Enter the Date of Birth:");  
String d=br.readLine();  
Date date=sdf.parse(d);  
List<Player>pl1=bo.findPlayer(playerList, date);  
System.out.format("%-15s %-15s %-15s %-20s %-15s %-15s %-15s  
%
s\n","Name","Date of Birth","Skill","Number of Wickets","Runs","Wickets","Nationality","Power  
Rating");  
for(Player p:pl1)  
{
System.out.format("%-15s %-15s %-15s %-20d %-15d %-15d %-15s  
.1f\n",p.getName(),sdf.format(p.getDateOfBirth()),p.getSkill(),p.getNumberOfMatches(),p.getRuns(),p.  
%
getWickets(),p.getNationality(),p.getPowerRating());  
}
break;  
case 3:  
System.out.println("Enter the Power Rating:");  
Double rating=Double.parseDouble(br.readLine());  
List<Player>pl2=bo.findPlayer(playerList, rating);  
System.out.format("%-15s %-15s %-15s %-20s %-15s %-15s %-15s  
%
s\n","Name","Date of Birth","Skill","Number of Wickets","Runs","Wickets","Nationality","Power  
Rating");  
for(Player p:pl2)  
{
System.out.format("%-15s %-15s %-15s %-20d %-15d %-15d %-15s  
.1f\n",p.getName(),sdf.format(p.getDateOfBirth()),p.getSkill(),p.getNumberOfMatches(),p.getRuns(),p.  
getWickets(),p.getNationality(),p.getPowerRating());  
%
}
break;  
default:  
System.out.println("Invalid choice");  
break;  
}
}
}
import java.util.Date;  
public class Player {  
//your code goes here...  
private String name;  
private java.util.Date dateOfBirth;  
private String skill;  
private Integer numberOfMatches;  
private Integer runs;  
private Integer wickets;  
private String nationality;  
private Double powerRating;  
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public java.util.Date getDateOfBirth() {  
return dateOfBirth;  
}
public void setDateOfBirth(java.util.Date dateOfBirth) {  
this.dateOfBirth = dateOfBirth;  
}
public String getSkill() {  
return skill;  
}
public void setSkill(String skill) {  
this.skill = skill;  
}
public Integer getNumberOfMatches() {  
return numberOfMatches;  
}
public void setNumberOfMatches(Integer numberOfMatches) {  
this.numberOfMatches = numberOfMatches;  
}
public Integer getRuns() {  
return runs;  
}
public void setRuns(Integer runs) {  
this.runs = runs;  
}
public Integer getWickets() {  
return wickets;  
}
public void setWickets(Integer wickets) {  
this.wickets = wickets;  
}
public String getNationality() {  
return nationality;  
}
public void setNationality(String nationality) {  
this.nationality = nationality;  
}
public Double getPowerRating() {  
return powerRating;  
}
public void setPowerRating(Double powerRating) {  
this.powerRating = powerRating;  
}
public Player(String name, Date dateOfBirth, String skill,  
Integer numberOfMatches, Integer runs, Integer wickets,  
String nationality, Double powerRating) {  
super();  
this.name = name;  
this.dateOfBirth = dateOfBirth;  
this.skill = skill;  
this.numberOfMatches = numberOfMatches;  
this.runs = runs;  
this.wickets = wickets;  
this.nationality = nationality;  
this.powerRating = powerRating;  
}
public Player() {  
super();  
}
}
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
public class PlayerBO {  
public List<Player> findPlayer(List<Player> playerList,String nationality){  
//your code goes here...  
List<Player> p1=new ArrayList<>();  
for(Player p:playerList)  
{
if(p.getNationality().equals(nationality))  
{
p1.add(p);  
}
}
return p1;  
}
public List<Player> findPlayer(List<Player> playerList,Date dateOfBirth){  
/your code goes here...  
List<Player> p2=new ArrayList<>();  
/
for(Player p:playerList)  
{
if(p.getDateOfBirth().equals(dateOfBirth))  
{
p2.add(p);  
}
}
return p2;  
}
public List<Player> findPlayer(List<Player> playerList,Double powerRating){  
//your code goes here...  
List<Player> p3=new ArrayList<>();  
for(Player p:playerList)  
{
if(p.getPowerRating().equals(powerRating))  
{
p3.add(p);  
}
}
return p3;  
}
}
Page of  
Team - Requirement 4  
Requirement 4:  
In this requirement, you need to sort the list of players based on number of matches  
played, runs scored or powerRating.  
a) Create a Class Player with the following attributes:  
Member Field Name  
name  
Type  
String  
dateOfBirth  
skill  
java.util.Date  
String  
numberOfMatches  
runs  
Integer  
Integer  
Integer  
String  
wickets  
nationality  
powerRating  
Double  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order: Player(String name, java.util.Date dateOfBirth, String skill, Integer  
numberOfMatches,Integer runs, Integer wickets, String nationality, Double  
powerRating)  
b) Create the following static methods in the Player class,  
Method Name  
Description  
This method accepts a String and returns a Player object. The player detail  
separated by commas is passed as value. This method will split the details  
and creates a player object and returns it.  
static Player  
createPlayer(String detail)  
The Player details should be given as a comma-separated value in the below order,  
name, dateOfBirth, skill, numberOfMatches, runs, wickets, nationality, powerRating  
c) The Player class should implement the Comparable interface which sorts the Player  
list based on the number of matches. While comparing, all the numberOfMatches  
attributes in the list are unique.  
d) Create a class PowerRatingComparator which implements Comparator interface  
and sort the Player list based on powerRating. While comparing, all the powerRating  
attributes in the list are unique.  
e) Create a class RunComparator which implements Comparator interface and sort the  
Player list based on the runs. While comparing, all the runs attributes in the list are  
unique.  
When the “player” object is printed, it should display the following details  
Print format:  
System.out.format("%-15s %-15s %-15s %-15s %-10s %-10s %-15s %s\n",  
"
Name","Date of birth","Skill","No of  
matches","Runs","wickets","Nationality","Power rating");  
Display one digit after decimal point for Double datatype.  
Sample Input and Output 1:  
Enter the number of the players:  
5
MS Dhoni,07-07-1981,Batsman,159,3561,0,India,4.4  
Virat Kohli,05-11-1988,Batsman,149,4418,4,India,4.7  
Ab de Villiers,7-02-1984,Batsman,129,3473,0,S Africa,4.6  
Mitchell Starc,30-01-1990,Bowler,27,96,34,Australia,4  
Bhuvneshwar,05-02-1990,Bowler,90,158,111,India,4.1  
Enter a type to sort:  
1
2
3
1
.Sort by number of matches played  
.Sort by runs scored  
.Sort by power rating  
Name  
Date of birth Skill  
No of matches Runs  
wickets  
Nationality Power rating  
Mitchell Starc 30-01-1990 Bowler  
27  
90  
96  
34  
111  
0
Australia  
Bhuvneshwar 05-02-1990 Bowler  
India 4.1  
Ab de Villiers 07-02-1984 Batsman 129  
4.0  
158  
3473  
4418  
3561  
S
Africa  
4.6  
Virat Kohli  
India  
05-11-1988 Batsman 149  
4.7  
4
MS Dhoni  
India  
07-07-1981 Batsman 159  
4.4  
0
Sample Input and Output 2:  
Enter the number of the players:  
5
MS Dhoni,07-07-1981,Batsman,159,3561,0,India,4.4  
Virat Kohli,05-11-1988,Batsman,149,4418,4,India,4.7  
Ab de Villiers,7-02-1984,Batsman,129,3473,0,S Africa,4.6  
Mitchell Starc,30-01-1990,Bowler,27,96,34,Australia,4  
Bhuvneshwar,05-02-1990,Bowler,90,158,111,India,4.1  
Enter a type to sort:  
1
2
3
2
.Sort by number of matches played  
.Sort by runs scored  
.Sort by power rating  
Name  
Date of birth Skill  
No of matches Runs  
wickets  
Nationality Power rating  
Mitchell Starc 30-01-1990 Bowler  
27  
90  
96  
34  
111  
0
Australia  
Bhuvneshwar 05-02-1990 Bowler  
India 4.1  
Ab de Villiers 07-02-1984 Batsman 129  
4.0  
158  
3473  
3561  
4418  
S
Africa  
4.6  
MS Dhoni  
India  
07-07-1981 Batsman 159  
4.4  
0
Virat Kohli  
India  
05-11-1988 Batsman 149  
4.7  
4
Sample Input and Output 3:  
Enter the number of the players:  
5
MS Dhoni,07-07-1981,Batsman,159,3561,0,India,4.4  
Virat Kohli,05-11-1988,Batsman,149,4418,4,India,4.7  
Ab de Villiers,7-02-1984,Batsman,129,3473,0,S Africa,4.6  
Mitchell Starc,30-01-1990,Bowler,27,96,34,Australia,4  
Bhuvneshwar,05-02-1990,Bowler,90,158,111,India,4.1  
Enter a type to sort:  
1
2
3
3
.Sort by number of matches played  
.Sort by runs scored  
.Sort by power rating  
Name  
Date of birth Skill  
No of matches Runs  
wickets  
Nationality Power rating  
Mitchell Starc 30-01-1990 Bowler  
27  
90  
96  
34  
111  
0
Australia  
4.0  
Bhuvneshwar 05-02-1990 Bowler  
158  
India  
4.1  
MS Dhoni  
India  
07-07-1981 Batsman 159  
4.4  
3561  
3473  
4418  
Ab de Villiers 07-02-1984 Batsman 129  
0
S
Africa  
4.6  
Virat Kohli  
India  
05-11-1988 Batsman 149  
4.7  
4
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Collections;  
import java.util.List;  
public class Main {  
public static void main(String args[]) throws NumberFormatException, IOException, ParseException{  
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
/
/Player pl=new Player();  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
List<Player> playerList=new ArrayList<>();  
System.out.println("Enter the number of the players:");  
/
/Your code here  
int n=Integer.parseInt(br.readLine());  
for(int i=0;i<n;i++)  
{
String detail=br.readLine();  
playerList.add(Player.createPlayer(detail));  
}
System.out.println("Enter a type to sort:\n1.Sort by number of matches played\n2.Sort  
by runs scored\n3.Sort by power rating");  
/
/Your code here  
int choice=Integer.parseInt(br.readLine());  
switch(choice)  
{
case 1:  
Collections.sort(playerList);  
System.out.format("%-15s %-15s %-15s %-15s %-10s %-10s %-15s %s\n",  
"Name","Date of birth","Skill","No of matches","Runs","wickets","Nationality","Power rating");  
for(Player p:playerList)  
{
System.out.format("%-15s %-15s %-15s %-15s %-10s %-10s %-15s  
%
s\n",  
p.getName(),sdf.format(p.getDateOfBirth()),p.getSkill(),p.getNumberOfMatches(),p.getRuns(),p.getWick  
ets(),p.getNationality(),p.getPowerRating());  
}
break;  
case 2:  
Collections.sort(playerList,new RunComparator() );  
System.out.format("%-15s %-15s %-15s %-15s %-10s %-10s %-15s %s\n",  
"Name","Date of birth","Skill","No of matches","Runs","wickets","Nationality","Power rating");  
for(Player p1:playerList)  
{
System.out.format("%-15s %-15s %-15s %-15s %-10s %-10s %-15s  
%
s\n",  
p1.getName(),sdf.format(p1.getDateOfBirth()),p1.getSkill(),p1.getNumberOfMatches(),p1.getRuns(),p1.  
getWickets(),p1.getNationality(),p1.getPowerRating());  
}
break;  
case 3:  
Collections.sort(playerList,new PowerRatingComparator());  
System.out.format("%-15s %-15s %-15s %-15s %-10s %-10s %-15s %s\n",  
"Name","Date of birth","Skill","No of matches","Runs","wickets","Nationality","Power rating");  
for(Player p2:playerList)  
{
System.out.format("%-15s %-15s %-15s %-15s %-10s %-10s %-15s  
%
s\n",  
p2.getName(),sdf.format(p2.getDateOfBirth()),p2.getSkill(),p2.getNumberOfMatches(),p2.getRuns(),p2.  
getWickets(),p2.getNationality(),p2.getPowerRating());  
}
break;  
}
}
}
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Date;  
public class Player implements Comparable<Player>{  
/
/Your code here  
private String name;  
private java.util.Date dateOfBirth;  
private String skill;  
private Integer numberOfMatches;  
private Integer runs;  
private Integer wickets;  
private String nationality;  
private Double powerRating;  
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public java.util.Date getDateOfBirth() {  
return dateOfBirth;  
}
public void setDateOfBirth(java.util.Date dateOfBirth) {  
this.dateOfBirth = dateOfBirth;  
}
public String getSkill() {  
return skill;  
}
public void setSkill(String skill) {  
this.skill = skill;  
}
public Integer getNumberOfMatches() {  
return numberOfMatches;  
}
public void setNumberOfMatches(Integer numberOfMatches) {  
this.numberOfMatches = numberOfMatches;  
}
public Integer getRuns() {  
return runs;  
}
public void setRuns(Integer runs) {  
this.runs = runs;  
}
public Integer getWickets() {  
return wickets;  
}
public void setWickets(Integer wickets) {  
this.wickets = wickets;  
}
public String getNationality() {  
return nationality;  
}
public void setNationality(String nationality) {  
this.nationality = nationality;  
}
public Double getPowerRating() {  
return powerRating;  
}
public void setPowerRating(Double powerRating) {  
this.powerRating = powerRating;  
}
public Player(String name, Date dateOfBirth, String skill,  
Integer numberOfMatches, Integer runs, Integer wickets,  
String nationality, Double powerRating) {  
super();  
this.name = name;  
this.dateOfBirth = dateOfBirth;  
this.skill = skill;  
this.numberOfMatches = numberOfMatches;  
this.runs = runs;  
this.wickets = wickets;  
this.nationality = nationality;  
this.powerRating = powerRating;  
}
public Player() {  
super();  
}
public static Player createPlayer(String detail) throws NumberFormatException, ParseException{  
/
/Your code here  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
String s[]=detail.split(",");  
Player p=new  
Player(s[0],sdf.parse(s[1]),s[2],Integer.parseInt(s[3]),Integer.parseInt(s[4]),Integer.parseInt(s[5]),s[6],Do  
uble.parseDouble(s[7]));  
return p;  
}
@Override  
public int compareTo(Player p1) {  
/
/ TODO Auto-generated method stub  
if(this.numberOfMatches>p1.numberOfMatches)  
return 1;  
else if(this.numberOfMatches<p1.numberOfMatches)  
return -1;  
else  
return 0;  
}
}
import java.util.Comparator;  
public class PowerRatingComparator implements Comparator<Player>{  
@
Override  
public int compare(Player r1, Player r2) {  
/ TODO Auto-generated method stub  
/
if(r1.getPowerRating()>r2.getPowerRating())  
return 1;  
else if(r1.getPowerRating()<r2.getPowerRating())  
return -1;  
else  
return 0;  
}
/
/Your code here  
}
import java.util.Comparator;  
public class RunComparator implements Comparator<Player>{  
@
Override  
public int compare(Player ru1, Player ru2) {  
/ TODO Auto-generated method stub  
/
if(ru1.getRuns()>ru2.getRuns())  
return 1;  
else if(ru1.getRuns()<ru2.getRuns())  
return -1;  
else  
return 0;  
}
/
/Your code here  
}
Page of  
Team - Requirement 5  
Requirement 5:  
In this requirement, given a list of players you need to find the number of players playing  
for a country using Map.  
a) Create a Class Player with the following attributes:  
Member Field Name  
name  
Type  
String  
dateOfBirth  
skill  
java.util.Date  
String  
numberOfMatches  
runs  
Integer  
Integer  
Integer  
String  
wickets  
nationality  
powerRating  
Double  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters. Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order:  
Player(String name, java.util.Date dateOfBirth, String skill, Integer  
numberOfMatches, Integer runs, Integer wickets, String nationality,  
DoublepowerRating)  
b) Create the following static methods in the Player class,  
Method Name  
Description  
This method accepts a list of Player as arguments and  
returns a TreeMap with the nationality as key and  
number of players playing for the country as value and  
returns the map.  
static Map<String,Integer>  
calculateNationalityCount(List<Player> list)  
In the TreeMap have the nationality as key and Count the number of players playing for  
the country and keep the number of players as value. Print the value sorted by country  
name.  
The player details should be given as a comma separated value in the below order,  
name, dateOfBirth, skill, numberOfMatches, runs, wickets, nationality, powerRating  
Print format:  
System.out.format("%-15s %s\n","Country","Count");  
Sample Input and Output 1:  
Enter the number of players:  
5
MS Dhoni,07-07-1981,Batsman,159,3561,0,India,4.4  
Virat Kohli,05-11-1988,Batsman,149,4418,4,India,4.7  
Bhuvneshwar,05-02-1990,Bowler,90,158,111,India,4.1  
Mike hussey,27-05-1975,Batsman,59,1977,0,Australia,4.5  
Mitchell Stark,30-01-1990,Bowler,27,96,34,Australia,4  
Country  
Australia  
India  
Count  
2
3
import java.util.Date;  
import java.util.List;  
import java.util.Map;  
import java.util.TreeMap;  
public class Player{  
/
/Your code here  
private String name;  
private java.util.Date dateOfBirth;  
private String skill;  
private Integer numberOfMatches;  
private Integer runs;  
private Integer wickets;  
private String nationality;  
private Double powerRating;  
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public java.util.Date getDateOfBirth() {  
return dateOfBirth;  
}
public void setDateOfBirth(java.util.Date dateOfBirth) {  
this.dateOfBirth = dateOfBirth;  
}
public String getSkill() {  
return skill;  
}
public void setSkill(String skill) {  
this.skill = skill;  
}
public Integer getNumberOfMatches() {  
return numberOfMatches;  
}
public void setNumberOfMatches(Integer numberOfMatches) {  
this.numberOfMatches = numberOfMatches;  
}
public Integer getRuns() {  
return runs;  
}
public void setRuns(Integer runs) {  
this.runs = runs;  
}
public Integer getWickets() {  
return wickets;  
}
public void setWickets(Integer wickets) {  
this.wickets = wickets;  
}
public String getNationality() {  
return nationality;  
}
public void setNationality(String nationality) {  
this.nationality = nationality;  
}
public Double getPowerRating() {  
return powerRating;  
}
public void setPowerRating(Double powerRating) {  
this.powerRating = powerRating;  
}
public Player(String name, Date dateOfBirth, String skill,  
Integer numberOfMatches, Integer runs, Integer wickets,  
String nationality, Double powerRating) {  
super();  
this.name = name;  
this.dateOfBirth = dateOfBirth;  
this.skill = skill;  
this.numberOfMatches = numberOfMatches;  
this.runs = runs;  
this.wickets = wickets;  
this.nationality = nationality;  
this.powerRating = powerRating;  
}
public Player() {  
super();  
}
public static Map<String,Integer> calculateNationalityCount(List<Player> list){  
/
/Your code here  
Map<String,Integer> cmap=new TreeMap<>();  
int n=0;  
for(Player p:list){  
if(cmap.containsKey(p.getNationality()))  
{
n=cmap.get(p.getNationality());  
n++;  
cmap.put(p.getNationality(), n);  
}
else  
cmap.put(p.getNationality(), 1);  
}
return cmap;  
}
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.List;  
import java.util.Map;  
public class Main {  
public static void main(String[] args) throws NumberFormatException, IOException,  
ParseException{  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
List<Player>list=new ArrayList<>();  
System.out.println("Enter the number of players:");  
/
/Your code here  
int n=Integer.parseInt(br.readLine());  
for(int i=0;i<n;i++){  
String s=br.readLine();  
String s1[]=s.split(",");  
Player p=new  
Player(s1[0],sdf.parse(s1[1]),s1[2],Integer.parseInt(s1[3]),Integer.parseInt(s1[4]),Integer.parseInt(s1[5]),  
s1[6],Double.parseDouble(s1[7]));  
list.add(p);  
}
Map<String,Integer> map=Player.calculateNationalityCount(list);  
System.out.format("%-15s %s\n","Country","Count");  
for(String pp:map.keySet())  
{
System.out.format("%-15s %d\n",pp,map.get(pp));  
}
}
}
Page of  
Team - Requirement 6  
Requirement 6:  
In this requirement, you need to find the country from which the maximum number of  
overseas players is taking part in the IPL.  
a)Create a Class Player with the following attributes:  
Member Field Name  
name  
Type  
String  
dateOfBirth  
skill  
java.util.Date  
String  
numberOfMatches  
runs  
Integer  
Integer  
Integer  
String  
wickets  
nationality  
powerRating  
Double  
Mark all the attributes as private, Create / Generate appropriate Getters & Setters, Add  
a default constructor and a parameterized constructor to take in all attributes in the  
given order: public Player(String name, java.util.Date dateOfBirth, String skill,  
Integer numberOfMatches, Integer runs, Integer wickets, String nationality,  
Double powerRating)  
b) Create the following static method in Player class,  
Method Name  
Description  
This method accepts a string which contains player details separa  
commas. Split the details and create a player object from the deta  
return the player object.  
public static Player  
createPlayer(String detail)  
This accepts a list as argument and returns a String. It takes a pla  
argument and returns the country from which the maximum numb  
players are playing.  
public static String  
highestCount(List<Player> playerList)  
The player details should be given as a comma-separated value in the below order,  
name,dateOfBirth,skill,numberOfMatches,runs,wickets,nationality,powerRating  
Create a driver class Main with the main method to get details and display details.  
Sample Input and Output:  
Enter the number of players:  
6
MS Dhoni,07-07-1981,Batsman,159,3561,0,India,4.4  
Virat Kohli,05-11-1988,Batsman,149,4418,4,India,4.7  
Bhuvneshwar,05-02-1990,Bowler,90,158,111,India,4.1  
Ab de Villiers,7-02-1984,Batsman,129,3473,0,S Africa,4.7  
Mitchell Stark,30-01-1990,Bowler,27,96,34,Australia,4.1  
Faf du Plessis,13-07-1984,Batsman,53,1295,0,S Africa,4.5  
The nationality with maximum players:India  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Date;  
import java.util.List;  
import java.util.Map;  
import java.util.TreeMap;  
public class Player {  
//write your code here  
private String name;  
private java.util.Date dateOfBirth;  
private String skill;  
private Integer numberOfMatches;  
private Integer runs;  
private Integer wickets;  
private String nationality;  
private Double powerRating;  
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public java.util.Date getDateOfBirth() {  
return dateOfBirth;  
}
public void setDateOfBirth(java.util.Date dateOfBirth) {  
this.dateOfBirth = dateOfBirth;  
}
public String getSkill() {  
return skill;  
}
public void setSkill(String skill) {  
this.skill = skill;  
}
public Integer getNumberOfMatches() {  
return numberOfMatches;  
}
public void setNumberOfMatches(Integer numberOfMatches) {  
this.numberOfMatches = numberOfMatches;  
}
public Integer getRuns() {  
return runs;  
}
public void setRuns(Integer runs) {  
this.runs = runs;  
}
public Integer getWickets() {  
return wickets;  
}
public void setWickets(Integer wickets) {  
this.wickets = wickets;  
}
public String getNationality() {  
return nationality;  
}
public void setNationality(String nationality) {  
this.nationality = nationality;  
}
public Double getPowerRating() {  
return powerRating;  
}
public void setPowerRating(Double powerRating) {  
this.powerRating = powerRating;  
}
public Player(String name, Date dateOfBirth, String skill,  
Integer numberOfMatches, Integer runs, Integer wickets,  
String nationality, Double powerRating) {  
super();  
this.name = name;  
this.dateOfBirth = dateOfBirth;  
this.skill = skill;  
this.numberOfMatches = numberOfMatches;  
this.runs = runs;  
this.wickets = wickets;  
this.nationality = nationality;  
this.powerRating = powerRating;  
}
public Player() {  
super();  
}
public static Player createPlayer(String detail) throws NumberFormatException,  
ParseException {  
/write your code here  
/
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
String s[]=detail.split(",");  
Player p=new  
Player(s[0],sdf.parse(s[1]),s[2],Integer.parseInt(s[3]),Integer.parseInt(s[4]),Intege  
r.parseInt(s[5]),s[6],Double.parseDouble(s[7]));  
return p;  
}
public static String highestCount(List<Player> playerList) {  
/
/write your code here  
int n=0;String s1="";  
Map<String,Integer>cmap=new TreeMap<>();  
for(Player p:playerList){  
if(cmap.containsKey(p.getNationality()))  
{
n=cmap.get(p.getNationality());  
n++;  
cmap.put(p.getNationality(), n);  
//System.out.println("bb");  
}
else  
cmap.put(p.getNationality(), 1);  
}
int max=0;  
for(String s:cmap.keySet())  
{
if(cmap.get(s)>=max)  
{
s1=s;  
max=cmap.get(s);  
/System.out.println(max);  
/
}
}
return s1;  
}
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.List;  
public class Main {  
public static void main(String args[]) throws NumberFormatException, IOException,  
ParseException {  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");  
System.out.println("Enter the number of players:");  
Integer count=Integer.parseInt(br.readLine());  
List<Player>playerList=new ArrayList<>();  
/
/write your code here  
for(int i=0;i<count;i++)  
{
String s=br.readLine();  
String s1[]=s.split(",");  
Player p1=new  
Player(s1[0],sdf.parse(s1[1]),s1[2],Integer.parseInt(s1[3]),Integer.parseInt(s1[4]),Integer.parseInt(s1[5]),  
s1[6],Double.parseDouble(s1[7]));  
playerList.add(p1);  
}
String h=Player.highestCount(playerList);  
System.out.println("The nationality with maximum players:"+h);  
}
}
Page of  
Validate customer details  
There are always typical human entry errors that need to be validated so that the data saved in  
the system are valid and can be used for later processing. Simple Rules that need to be taken  
care:  
Create a Class named as Main, which contains the following methods,  
No  
1
Method Name  
public static void parseName(BufferedReader br)  
public static void isValidEmail(BufferedReader br)  
public static void playContactNumber(BufferedReader br)  
public static void userLifeTime(BufferedReader br)  
2
3
4
parseName ( ):  
The customer name contains first name and last name separated by any “special character”.  
Given a name, display the first and last name.  
Examples of Special character like: ' , ' , '@' , '#' , . . . . . (NOTE: There can be any special  
character).  
isValidEmail ( ):  
Check if the email address entered is valid. A Valid email address would end with 3 domains  
(com, org, net) and would contain a “@”.  
playContactNumber ( ):  
Every contact number would be in the format (ISD Code-STD Code-Number). The size of the  
fields would be (3 digits 4 digits 10 digits). Given a contact number, find the sum of last 10  
digits until it reaches to a single digit. Print the digit.  
userLifeTime ( ):  
Given a “createdOn” Date, print number of minutes before which the user was created. Assume  
the current date to be ‘28-07-2017 09:00’.  
Date format : "dd/MM/yyyy HH:mm";  
Example for LifeTime calculation:  
If the createdOn date is "28-07-2017 08:20", then the life time is 40 minutes.  
Sample Input and Output:  
Menu  
1
2
3
4
5
1
. Parse Name  
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
Enter name:  
John%Abraham*Lincoln  
John Abraham Lincoln  
Menu  
1
2
3
4
5
1
. Parse Name  
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
Enter name:  
Marc;Farnando  
Marc Farnando  
Menu  
1
2
3
4
5
2
. Parse Name  
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
Enter E-mail id:  
Email is invalid  
Menu  
1
2
3
4
5
2
. Parse Name  
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
Enter E-mail id:  
john@.com  
Email is invalid  
Menu  
1. Parse Name  
2
3
4
5
2
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
Email id is valid  
Menu  
1
2
3
4
5
3
. Parse Name  
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
Enter contact number:  
44-7485-44784578459  
8
Contact number invalid  
Menu  
1
2
3
4
5
3
. Parse Name  
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
Enter contact number:  
8-847-8547123654  
5
Contact number invalid  
Menu  
1
2
3
4
5
3
. Parse Name  
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
Enter contact number:  
47-7845-9557898865  
8
Sum of contact number: 7  
Menu  
1
2
3
4
5
. Parse Name  
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
4
Enter Created on date(dd-MM-yyyy HH:mm):  
25-07-2017 10:30  
Life time is: 4230 minutes  
Menu  
1
2
3
4
5
5
. Parse Name  
. Valid Email  
. Play Contact Number  
. User Lifetime  
. Exit  
import java.io.*;  
import java.text.SimpleDateFormat;  
import java.util.*;  
public class Main {  
public static void main(String[] args) throws Exception{  
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
String sb = "Menu\n1. Parse Name\n2. Valid Email\n3. Play Contact Number\n4.  
User Lifetime\n5. Exit";  
while(true)  
{
System.out.println(sb);  
int inp = Integer.parseInt(br.readLine());  
switch(inp) {  
case 1:  
/
/fill code here.  
parseName(br);  
break;  
case 2:  
/
/fill code here.  
isValidEmail(br);  
break;  
case 3:  
/
/fill code here.  
playContactNumber(br);  
break;  
case 4:  
/
/fill code here.  
userLifeTime(br);  
break;  
case 5:  
/
/fill code here.  
System.exit(0);  
}
}
}
public static void parseName(BufferedReader br) throws Exception  
{
System.out.println("Enter name:");  
String name = br.readLine();  
/
/fill code here.  
char ch[]=name.toCharArray();  
for(int i=0;i<ch.length;i++)  
{
if(!Character.isAlphabetic(ch[i]))  
{
System.out.println(" ");  
}
else  
System.out.print(ch[i]);  
}
System.out.println();  
}
public static void isValidEmail(BufferedReader br) throws Exception  
{
System.out.println("Enter E-mail id:");  
String email = br.readLine();  
if(email.contains("@")&&(email.endsWith(".com")||email.endsWith(".org")||email.endsWit  
h(".net")))  
{
String a[]=email.split("@");  
if(a[1].length()>4)  
System.out.println("Email id is valid");  
else  
System.out.println("Email is invalid");  
}
else  
System.out.println("Email is invalid");  
}
public static void playContactNumber(BufferedReader br) throws Exception  
{
System.out.println("Enter contact number:");  
String number = br.readLine();  
int k=0;  
/
/fill code here.  
if((number.matches("[0-9]{3}[-]{1}[0-9]{4}[-]{1}[0-9]{10}"))&&(number.length()==19))  
{
{
for(int i=9;i<number.length();i++)  
k=k+Integer.parseInt(number.substring(i,i+1));  
while(k>9)  
{
k=k%10+k/10;  
}
}
System.out.println("Sum of contact number: "+k);  
}
else  
System.out.println("Contact number invalid");  
}
public static void userLifeTime(BufferedReader br) throws Exception  
{
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm");  
Date startDate = sdf.parse("28-07-2017 09:00");  
System.out.println("Enter Created on date(dd-MM-yyyy HH:mm):");  
/
/fill code here.  
String k=br.readLine();  
Date endDate=sdf.parse(k);  
long s=Math.abs(startDate.getTime()-endDate.getTime());  
System.out.println("Life time is: "+(s/60000)+" minutes");  
}
}
Page of  
p { margin-bottom: 0.25cm; border: medium none; padding: 0cm;  
direction: ltr; line-height: 120%; text-align: left; }a:link { }  
Client Interview Preparation  
You are on the verge of completing your training and being on-boarded  
to your first project. Before on-boarding, you are required to take up a  
client interview. Your academy wants to ensure that you clear the  
interview with flying colors. In a quick brainstorming, they thought  
every project would have an end user (Customer and Address). So they  
decided to frame questions based on these two classes.  
Customer Comparison  
Create a class named as Customer, which contains following private  
variables/ attributes,  
Member Field  
Type  
name  
id  
Long  
name  
gender  
email  
String  
Character (M/F)  
String  
contactNumber String  
Date (time in 24 hrs clock)  
dd/MM/yyyy HH:mm:ss  
createdOn  
Mark all the attributes as private  
Create / Generate appropriate Getters & Setters.  
Add a default constructor and a parameterized constructor to take in  
all attributes.  
When the “customer” object is printed, it should display the following  
details: (override toString method)  
Customer: name  
Customer contact details: contactNumber, email  
Two members are considered same if they have same email and  
contactNumber. Implement the logic in the appropriate function.  
(override equals method)  
Input format:  
By default, there are only two customers. More details in Sample IO.  
Output format:  
If both the customers are same then print "Customer 1 is same as  
Customer 2" without quotes.  
Otherwise, print "Customer 1 and Customer 2 are different" without  
quotes.  
Refer Sample Input and Outputs.  
HINT:  
Please print customer id in the Main class.  
The toString method should print as specified in the problem  
statement [ Name and contact details alone]  
Sample Input and Output 1:  
Customer1 :  
id:  
45  
name:  
John  
Gender:  
M
contact number:  
+
997-4854-7485965123  
createdOn:  
2/10/2016 09:30:00  
1
Customer2 :  
id:  
12  
name:  
Marc  
Gender:  
M
contact number:  
+
997-4854-7485965123  
createdOn:  
1/10/2016 10:00:00  
1
Customer id 45  
Customer: John  
Customer contact details:+997-4854-7485965123, john@a.com  
Customer id 12  
Customer: Marc  
Customer contact details:+997-4854-7485965123, marc@a.com  
Customer 1 and Customer 2 are different  
Sample Input and Output 2:  
Customer1 :  
id:  
12  
name:  
James William  
Gender:  
M
contact number:  
+
88-7489-9958748512  
createdOn:  
5/02/2017 10:00:00  
1
Customer2 :  
id:  
78  
name:  
James Camron  
Gender:  
M
contact number:  
+
88-7489-9958748512  
createdOn:  
3/03/2017 16:30:00  
0
Customer id 12  
Customer: James William  
Customer contact details:+88-7489-9958748512, james@a.com  
Customer id 78  
Customer: James Camron  
Customer contact details:+88-7489-9958748512, james@a.com  
Customer 1 is same as Customer 2  
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.Iterator;  
public class Main {  
public static void main(String[] args) throws IOException,  
ParseException {  
String id,name,email,contactNumber,createdOn,gender;  
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy  
HH:mm:ss");  
BufferedReader br = new BufferedReader(new  
InputStreamReader(System.in));  
int i;  
ArrayList<Customer> customerList = new ArrayList<>();  
for(i=0;i<2;i++) {  
System.out.println("Customer"+(i+1)+" :");  
System.out.println("id: ");  
id = br.readLine();  
System.out.println("name: ");  
name = br.readLine();  
System.out.println("Gender: ");  
gender = br.readLine();  
System.out.println("email: ");  
email = br.readLine();  
System.out.println("contact number: ");  
contactNumber = br.readLine();  
System.out.println("createdOn: ");  
createdOn = br.readLine();  
Date d = sdf.parse(createdOn);  
Customer c = new  
Customer(Long.parseLong(id),name,gender.charAt(0),email,contactNum  
ber,d);  
customerList.add(c);  
}
for(Customer c : customerList)  
{
System.out.println("Customer id "+c.getId());  
System.out.println(c);  
}
Iterator<Customer> iter1=customerList.iterator();  
Customer c1=iter1.next();  
Customer c2=iter1.next();  
/
/fill code here.  
if(c1.equals(c2)) {  
System.out.println("Customer 1 is same as Customer 2");  
}
else {  
System.out.println("Customer 1 and Customer 2 are different");  
}
}
}
import java.util.Date;  
public class Customer {  
@Override  
public int hashCode() {  
final int prime = 31;  
int result = 1;  
result = prime * result  
+
((contactNumber == null) ? 0 : contactNumber.hashCode());  
result = prime * result + ((email == null) ? 0 : email.hashCode());  
return result;  
}
@Override  
public boolean equals(Object obj) {  
if (this == obj)  
return true;  
if (obj == null)  
return false;  
if (getClass() != obj.getClass())  
return false;  
Customer other = (Customer) obj;  
if (contactNumber == null) {  
if (other.contactNumber != null)  
return false;  
}
else if (!contactNumber.equals(other.contactNumber))  
return false;  
if (email == null) {  
if (other.email != null)  
return false;  
}
else if (!email.equals(other.email))  
return false;  
return true;  
}
@Override  
public String toString() {  
return "Customer: "+getName()+"\nCustomer contact  
details:"+getContactNumber()+", "+getEmail();  
}
private Long id;  
private String name;  
private char gender;  
private String email;  
private String contactNumber;  
private Date createdOn;  
public Customer()  
{
}
public Customer(Long id, String name, char gender, String email,  
String contactNumber, Date createdOn) {  
this.name = name;  
this.gender = gender;  
this.email = email;  
this.contactNumber = contactNumber;  
this.createdOn = createdOn;  
}
public Long getId() {  
return id;  
}
public void setId(Long id) {  
this.id = id;  
}
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public char getGender() {  
return gender;  
}
public void setGender(char gender) {  
this.gender = gender;  
}
public String getEmail() {  
return email;  
}
public void setEmail(String email) {  
this.email = email;  
}
public String getContactNumber() {  
return contactNumber;  
}
public void setContactNumber(String contactNumber) {  
this.contactNumber = contactNumber;  
}
public Date getCreatedOn() {  
return createdOn;  
}
public void setCreatedOn(Date createdOn) {  
this.createdOn = createdOn;  
}
}
Page of  
Overloading - Payment  
With all the software systems that are being built, one of the widely  
used utilities in the financial sector is payments through various  
channels. The widely used channels are OnlineBanking, CreditCard and  
Wallet. The banks generate revenue by charging a small margin as part  
of the usage. Create a class called PaymentUtil. Overload a method  
makePayment” as given below in the specification and calculate the  
total payment amount.  
Create a class named as PaymentUtil, which contains following Overload  
methods,  
No Method Name  
Method Description  
This method calculates the  
total amount (amount +  
service tax amount). Here  
the tax percent gets varied  
depending on the bank.  
Fetch the corresponding  
service tax from a map  
collection by bank name.  
Map<String bankName, Float  
serviceTax>  
public Double  
makePayment(Map<String,Float>  
bankTax,String bankName,Double  
amount)  
1
This map is prefilled. Only  
banks present in the map  
would be part of input.  
public Double makePayment(Double This method calculates the  
amount) total amount (include service  
2
tax and value added  
tax(VAT). First, calculate  
the service tax amount and  
then calculate the VAT  
amount.  
[
VAT % is applied on total  
amount+service tax ]  
This method calculates the  
total amount, which is a  
discount from the amount  
with parameterized discount  
percentage.  
public Double makePayment(Double  
amount, Float discountPercent)  
3
Create the class named as Main, which contains the main method. Input  
and output operations will be done in the main method.  
It calls various methods in PaymentUtil class to perform the task.  
The following data will be placed inside the static block in the Main  
class  
onlineBankingMap.put("ICICI", 4.2f);  
onlineBankingMap.put("IBRD", 3f);  
onlineBankingMap.put("IFC", 4.9f);  
onlineBankingMap.put("HSBC", 3.9f);  
That data will provide in template code.  
Problem Specification:  
Overload a method “makePayment” as given in the specification and  
calculate the total payment amount.  
The bank name is case insensitive.  
The service tax for credit card is 5.2%.  
The VAT for the credit card is 2.3%.  
The discount percentege for Wallet is 20.2%.  
Input and Output format:  
Refer Sample Input and Output.  
Sample Input and Output:  
1. Online banking  
2
3
. Credit card  
. Wallet  
Enter the choice:  
1
Enter the user name:  
ICICI74484  
Enter the password:  
Mu7485  
Enter the amount:  
12560  
Enter the bank name:  
icici  
Total amount(Inclusive of Service Tax): 13087.52  
Sample Input and Output 2:  
1. Online banking  
2
3
. Credit card  
. Wallet  
Enter the choice:  
2
Enter the account number:  
8458 9665 7485 2256  
Enter the pin:  
8
451  
Enter the amount:  
6300  
1
Total amount(Inclusive of Service Tax and VAT): 17541.99  
Sample Input and Output 3:  
1. Online banking  
2
3
. Credit card  
. Wallet  
Enter the choice:  
3
Enter the user name:  
HSBC7457  
Enter the password:  
Yu67488  
Enter the amount:  
2
8500  
Discounted amount: 22743.00  
import java.io.*;  
import java.text.DecimalFormat;  
import java.util.HashMap;  
import java.util.Map;  
public class Main {  
static Float discount = 20.2f;  
static Map<String, Float> onlineBanking;  
static  
{
onlineBanking = new HashMap<>();  
onlineBanking.put("ICICI", 4.2f);  
onlineBanking.put("IBRD", 3f);  
onlineBanking.put("IFC", 4.9f);  
onlineBanking.put("HSBC", 3.9f);  
}
public static void main(String[] args) throws Exception {  
BufferedReader br = new BufferedReader(new  
InputStreamReader(System.in));  
Double amount;  
Double totalPayment;  
PaymentUtil paymentUtil = new PaymentUtil();  
String userName,password;  
StringBuilder stringBuilder = new StringBuilder();  
stringBuilder.append("1. Online banking\n").append("2. Credit  
card\n").append("3. Wallet\n")  
.append("Enter the choice:");  
System.out.println(stringBuilder.toString());  
Integer choice = new Integer(br.readLine());  
DecimalFormat df = new DecimalFormat("#.00");  
switch(choice)  
{
case 1:  
System.out.println("Enter the user name:");  
userName = br.readLine();  
System.out.println("Enter the password:");  
password = br.readLine();  
System.out.println("Enter the amount:");  
amount = new Double(br.readLine());  
System.out.println("Enter the bank name:");  
String bankName = br.readLine();  
System.out.println("Total amount(Inclusive of Service Tax):  
+df.format(paymentUtil.makePayment(onlineBanking, bankName,  
"
amount)));  
break;  
case 2:  
String accNo;  
Integer pin;  
System.out.println("Enter the account number:");  
accNo = (br.readLine());  
System.out.println("Enter the pin:");  
pin = new Integer(br.readLine());  
System.out.println("Enter the amount:");  
amount = new Double(br.readLine());  
System.out.println("Total amount(Inclusive of Service Tax  
and VAT): "+df.format(paymentUtil.makePayment(amount)));  
break;  
case 3:  
System.out.println("Enter the user name:");  
userName = br.readLine();  
System.out.println("Enter the password:");  
password = br.readLine();  
System.out.println("Enter the amount:");  
amount = new Double(br.readLine());  
System.out.println("Discounted amount:  
"
+df.format(paymentUtil.makePayment(amount, discount)));  
break;  
}
}
}
import java.util.Map;  
import java.util.Map.Entry;  
import java.util.Set;  
public class PaymentUtil {  
public Double makePayment(Map<String,Float> bankTax,String  
bankName,Double amount)  
{
Set<String> keys = bankTax.keySet();  
double amnt=0;  
for(String s : keys)  
{
if(s.equalsIgnoreCase(bankName))  
{
amnt=bankTax.get(s);  
}
}
return amount+(amount*(amnt/100));  
}
public Double makePayment(Double amount)  
{
Float serviceTax = 5.2f;  
Float vat = 2.3f;  
double d1=amount+(amount*serviceTax/100);  
return d1+(d1*(vat/100));  
}
public Double makePayment(Double amount, Float discountPercent)  
{
return amount-(amount*(discountPercent/100));  
}
}
Page of  
Find customer by id and state  
Create a class named as Customer, which contains following private variable/ attributes,  
Member Field  
Type  
name  
id  
Long  
name  
String  
gender  
email  
Character (M/F)  
String  
contactNumber  
String  
Date (time in 24 hrs clock) dd/MM/yyyy  
HH:mm:ss  
createdOn  
address  
Address  
Mark all the attributes as private  
Create / Generate appropriate Getters & Setters.  
Add a default constructor and a parameterized constructor to take in all attributes.  
Implement the following methods in the Customer class:  
No Method Name  
Method Description  
In this method, that takes up an id  
public Customer findCustomerById(List<Customer> and returns a matching customer  
1
2
customerList, Long id)  
object. If the object is not found  
then return null.  
In this method, given a state as a  
parameter, print the list of  
customers who belong to the state.  
public List<Customer>  
findCustomerListByState(List<Customer>  
customerList, String state)  
Create a class named as Address, which contains following private variable/ attributes,  
Member Field name  
Type  
street  
city  
String  
String  
String  
String  
state  
country  
zipCode  
Integer  
Include appropriate getters and setters.  
Add a default constructor and a parameterized constructor to take in all attributes.  
The customer details will be populated in a static block in this class(provide in the template code).  
Refer Sample Input and Output.  
Use the following format for specified output.  
"
%-15s %-20s %-15s %-15s %s\n", "Name", "Email", "City", "Country", "Zipcode"  
Problem Specification:  
If the customer with the id is not found then print "No Customer with that id" without quotes.  
If none of the customer belongs to the state then print "No customer belongs that state" without quotes.  
Sample Input and Output 1:  
Menu  
1. Find customer by id  
2. Find customer by states  
Enter the choice:  
1
Enter the Id to find customer:  
5
Customer Name: Tedmond  
Contact Number: +88-7844-8854799658  
Street: Port Townsend  
City: Tacoma  
State: Washington  
Country: USA  
Zip code: 98412  
Sample Input and Output 2:  
Menu  
1. Find customer by id  
2. Find customer by states  
Enter the choice:  
2
Enter the state:  
Texas  
Name  
Email  
Contact no  
Street City  
CountryZipcode  
+
78-7485-  
Avenue Plano  
USA  
75025  
79404  
77591  
9
555874846  
+78-9855-  
Parc St Lubbock USA  
Wall Texas  
7
488742136  
+89-7748-  
USA  
8
859112478 Street City  
main  
import java.io.*;  
import java.text.SimpleDateFormat;  
import java.util.*;  
public class Main {  
static List<Customer> customerList;  
static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");  
static  
{
customerList = new ArrayList<>();  
try  
{
customerList.add(new Customer(1, "John Smith",'M', "johnsmith@a.com", "+98-7488-  
8
9
7
7
8
8
554744596",sdf.parse("15/02/2017 16:30:00"),  
new Address("15th St","Buffalo", "New York", "USA", 14220)));  
customerList.add(new Customer(2, "Aekerman",'M', "aekerman@a.com","+78-7485-  
555874846",sdf.parse("18/03/2017 15:45:00"),  
new Address("Avenue","Plano", "Texas", "USA", 75025)));  
customerList.add(new Customer(3, "Madeleine",'F', "madeleine@a.com", "+78-9855-  
488742136",sdf.parse("22/02/2017 16:45:00"),  
new Address("Parc St","Lubbock", "Texas", "USA", 79404)));  
customerList.add(new Customer(4, "Edrick",'M', "edrick@a.com", "+99-8787-  
844859978",sdf.parse("15/03/2017 15:45:00"),  
new Address("145th St","Wasilla", "Alaska", "USA", 99629)));  
customerList.add(new Customer(5, "Tedmond", 'M', "tedmond@a.com", "+88-7844-  
854799658",sdf.parse("15/03/2017 15:45:00"),  
new Address("Port Townsend","Tacoma", "Washington", "USA", 98412)));  
customerList.add(new Customer(6, "Nelson",'M', "nelson@a.com", "+88-7848-  
857488956",sdf.parse("17/05/2017 10:35:00"),  
new Address("1st St","Akron", "Ohio", "USA", 44304)));  
customerList.add(new Customer(7, "Dalton", 'M', "dalton@a.com", "+88-8879-  
854741124",sdf.parse("01/05/2017 17:25:00"),  
8
new Address("Lake city", "Newburgh", "New York", "USA", 12550)));  
customerList.add(new Customer(8, "Raymond", 'M', "raymond@a.com", "+89-7748-  
859112478",sdf.parse("17/06/2017 08:45:00"),  
8
new Address("Wall Street","Texas City", "Texas", "USA", 77591)));  
customerList.add(new Customer(9, "Rosemary", 'F', "rosemary@a.com", "+89-7844-8857489958",  
sdf.parse("22/04/2017 16:15:00"),  
new Address("Georgetown","Olympia", "Washington", "USA", 98506)));  
customerList.add(new Customer(10, "Ruford", 'M', "ruford@a.com", "+88-7485-8597448596",  
sdf.parse("12/02/2017 09:05:00"),  
new Address("Baker street", "Miles City", "Montana", "USA", 59301)));  
}
catch(Exception e)  
{
e.printStackTrace();  
}
}
public static void main(String[] args) throws Exception {  
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));  
System.out.println("Menu\n1. Find customer by id\n2. Find customer by states\nEnter the choice:");  
switch(new Integer(bufferedReader.readLine()))  
{
case 1:  
System.out.println("Enter the Id to find customer:");  
Customer c=new Customer().findCustomerById(customerList, new Integer(bufferedReader.readLine()));  
if(c!=null)  
{
System.out.println("Customer Name: "+c.getName());  
System.out.println("Gender: "+c.getGender());  
System.out.println("Email: "+c.getEmail());  
System.out.println("Contact Number: "+c.getContactNumber());  
System.out.println("Street: "+c.getAddress().getStreet());  
System.out.println("City: "+c.getAddress().getCity());  
System.out.println("State: "+c.getAddress().getState());  
System.out.println("Country: "+c.getAddress().getCountry());  
System.out.println("Zip code: "+c.getAddress().getZipCode());  
}
else  
System.out.println("No Customer with that id");  
break;  
case 2:  
System.out.println("Enter the state:");  
List<Customer> clist=new Customer().findCustomerListByState(customerList, bufferedReader.readLine());  
if(!(clist.isEmpty()))  
{
System.out.format("%-15s %-20s %-20s %-15s %-15s %-15s %s\n","Name","Email", "Contact  
no","Street","City","Country","Zipcode");  
for(Customer c1:clist){  
System.out.format("%-15s %-20s %-20s %-15s %-15s %-15s %d\n",c1.getName(),c1.getEmail(),  
c1.getContactNumber(),c1.getAddress().getStreet(),c1.getAddress().getCity(),c1.getAddress().getCountry(),c1.getAd  
dress().getZipCode());  
}
}
else  
System.out.println("No customer belongs that state");  
break;  
}
}
}
customer  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
public class Customer {  
private int id;  
private String name;  
private Character gender;  
private String email;  
private String contactNumber;  
private Date createdOn;  
private Address address;  
public Address getAddress() {  
return address;  
}
public void setAddress(Address address) {  
this.address = address;  
}
public Customer(int id, String name, Character gender, String email,  
String contactNumber, Date createdOn, Address address) {  
super();  
this.name = name;  
this.gender = gender;  
this.email = email;  
this.contactNumber = contactNumber;  
this.createdOn = createdOn;  
this.address = address;  
}
@Override  
public String toString() {  
return "Customer: "+name+"\nCustomer contact details:"+contactNumber+", "+email;  
}
public Customer() {  
super();  
/
}
/ TODO Auto-generated constructor stub  
public int getId() {  
return id;  
}
public void setId(int id) {  
}
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public Character getGender() {  
return gender;  
}
public void setGender(Character gender) {  
this.gender = gender;  
}
public String getEmail() {  
return email;  
}
public void setEmail(String email) {  
this.email = email;  
}
public String getContactNumber() {  
return contactNumber;  
}
public void setContactNumber(String contactNumber) {  
this.contactNumber = contactNumber;  
}
public Date getCreatedOn() {  
return createdOn;  
}
public void setCreatedOn(Date createdOn) {  
this.createdOn = createdOn;  
}
public static Customer findCustomerById(List<Customer> customerList, int id){  
Customer c=null;  
for(Customer c1:customerList){  
if(c1.getId()==id)  
c=c1;  
}
return c;  
}
public static List<Customer> findCustomerListByState(List<Customer> customerList, String state){  
List<Customer> clist=new ArrayList<Customer>();  
for(Customer c:customerList){  
if(c.getAddress().getState().equalsIgnoreCase(state))  
clist.add(c);  
}
return clist;  
}
}
address  
public class Address {  
private String street,city,state,country;  
private int zipCode;  
public String getStreet() {  
return street;  
}
public void setStreet(String street) {  
this.street = street;  
}
public String getCity() {  
return city;  
}
public void setCity(String city) {  
this.city = city;  
}
public String getState() {  
return state;  
}
public void setState(String state) {  
this.state = state;  
}
public String getCountry() {  
return country;  
}
public void setCountry(String country) {  
this.country = country;  
}
public int getZipCode() {  
return zipCode;  
}
public void setZipCode(int zipCode) {  
this.zipCode = zipCode;  
}
public Address(String street, String city, String state, String country,  
int zipCode) {  
super();  
this.street = street;  
this.city = city;  
this.state = state;  
this.country = country;  
this.zipCode = zipCode;  
}
public Address() {  
super();  
/
}
/ TODO Auto-generated constructor stub  
}
Page of  
Batch Processing  
Usually, As part of batch processing jobs, a CSV or TXT file is read, relevant objects are created and database is populated with CSV contents.  
Create the list of customer objects with the CSV content provided in the sample IO.  
Create a class named as Customer, which contains following private variable/ attributes,  
Member Field  
Type  
name  
id  
Long  
name  
String  
gender  
email  
Character (M/F)  
String  
contactNumber  
String  
Date (time in 24 hrs clock) dd/MM/yyyy  
HH:mm:ss  
createdOn  
Mark all the attributes as private  
Create / Generate appropriate Getters & Setters.  
Add a default constructor and a parameterized constructor to take in all attributes.  
In the Customer class, implement the following methods.  
No Method Name  
Method Description  
In this method, given parameter is  
the list of customer details in a  
string format where each data is  
separated by a comma. Parse the  
string and create a customer  
arrayList.  
public static List<Customer>  
populateCustomers(List<String> csvList)  
1
In this method, given part of  
customer name, search the  
customer list based on name and  
return the customer list with  
matching names.  
public static List<Customer>  
findCustomerNameFromList(List<Customer>  
customers, String subString)  
2
Input format:  
The first input consists of an integer that corresponds to the number of customer n.  
The next n line of the input consists of a string that corresponds to the customer details, which is separated by a comma.  
Input sequence:  
id, name, gender, email, contactNumber, createdOn.  
The last input is the substring that used to search the specified customers.  
Output format:  
Refer Sample Input and Output.  
HINT:  
The implementation can either be done in the BO class or static method in the customer class.  
In real time projects, its done in the BO Class and a fallback is given the customer class as static method.  
Ensure the static methods in the Customer class is present.  
The implementation can be in the BO layer with the static methods calling the methods in BO layer.  
Main - Customer class static methods - CustomerBO methods.  
Sample Input and Output:  
Enter the number of customer:  
5
Enter the customer 1 detail:  
1
2,John Smith,M,johnsmith@a.com,+85-7489-8596478596,12/12/2016 12:30:00  
Enter the customer 2 detail:  
5,Tedmond,M,tedmond@a.com,+45-9857-5266987485,14/01/2017 04:30:00  
1,Dalton,M,dalton@a.com,+48-8967-7485947558,12/02/2017 20:00:00  
Enter the customer 4 detail:  
,Raymond,M,raymond@a.com,+88-8745-8554712569,28/01/2017 10:30:00  
,Ruford,M,ruford@a.com,+88-4859-7714589633,01/04/2017 17:45:00  
1
1
5
9
Id Name  
John  
Smith  
5 Tedmond M  
Gender Email  
Contact no  
+85-7489-  
8596478596  
Created on  
12/12/2016  
12:30:00  
14/01/2017  
04:30:00  
12/02/2017  
20:00:00  
28/01/2017  
10:30:00  
01/04/2017  
17:45:00  
1
1
1
5
9
2
M
+45-9857-  
5
266987485  
+48-8967-  
1 Dalton  
Raymond M  
Ruford  
M
7
485947558  
+88-8745-  
8
554712569  
+88-4859-  
M
7
714589633  
Enter the substring to search from customer list:  
mon  
Id Name  
Gender Email  
Contact no  
Created on  
+
45-9857-  
14/01/2017  
04:30:00  
28/01/2017  
10:30:00  
1
5
5 Tedmond M  
Raymond M  
5
266987485  
+88-8745-  
8
554712569  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
public class Customer {  
private Long id;  
private String name;  
private Character gender;  
private String email;  
private String contactNumber;  
private Date createdOn;  
public Customer(Long id, String name, Character gender, String email,  
String contactNumber, Date createdOn) {  
this.gender = gender;  
this.email = email;  
this.contactNumber = contactNumber;  
this.createdOn = createdOn;  
}
public Long getId() {  
return id;  
}
public void setId(Long id) {  
}
public String getName() {  
return name;  
}
public void setName(String name) {  
}
public Character getGender() {  
return gender;  
}
public void setGender(Character gender) {  
this.gender = gender;  
}
public String getEmail() {  
return email;  
}
public void setEmail(String email) {  
this.email = email;  
}
public String getContactNumber() {  
return contactNumber;  
}
public void setContactNumber(String contactNumber) {  
this.contactNumber = contactNumber;  
}
public Date getCreatedOn() {  
return createdOn;  
}
public void setCreatedOn(Date createdOn) {  
this.createdOn = createdOn;  
}
/
/Generate getters and setters.  
public static List<Customer> populateCustomers(List<String> csvList) throws NumberFormatException, ParseException{  
List<Customer> a = new ArrayList<Customer>();  
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:SS");  
for(int i=0;i<csvList.size();i++){  
String b[] = csvList.get(i).split(",");  
Customer c = new Customer(Long.parseLong(b[0]), b[1], b[2].charAt(0), b[3], b[4], sdf.parse(b[5]));  
a.add(c);  
}
return a;  
}
public static List<Customer> findCustomerNameFromList(List<Customer> customers, String subString){  
List<Customer> a = new ArrayList<Customer>();  
for(int i=0;i<customers.size();i++){  
if(customers.get(i).name.contains(subString)){  
a.add(customers.get(i));  
}
}
return a;  
}
}
import java.text.SimpleDateFormat;  
import java.util.*;  
public class CustomerAddressBO {  
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");  
public List<Customer> populateCustomers(List<String> csvList) throws Exception  
{
/
/fill code here.  
List<Customer> a = new ArrayList<Customer>();  
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:SS");  
for(int i=0;i<csvList.size();i++){  
String b[] = csvList.get(i).split(",");  
Customer c = new Customer(Long.parseLong(b[0]), b[1], b[2].charAt(0), b[3], b[4], sdf.parse(b[5]));  
a.add(c);  
}
return a;  
}
public List<Customer> findCustomerNameFromList(List<Customer>customers,String subString) throws Exception  
{
/
/fill code here.  
List<Customer> a = new ArrayList<Customer>();  
for(int i=0;i<customers.size();i++){  
if(customers.get(i).getName().contains(subString)){  
a.add(customers.get(i));  
}
}
return a;  
}
}
import java.io.BufferedReader;  
import java.io.InputStreamReader;  
import java.text.SimpleDateFormat;  
import java.util.ArrayList;  
import java.util.List;  
public class Main {  
public static void main(String[] args) throws Exception {  
CustomerAddressBO customerAddressBO = new CustomerAddressBO();  
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
System.out.println("Enter the number of customer:");  
int n = new Integer(br.readLine());  
List<String> csvList = new ArrayList<>();  
for(int i = 0; i<n ;i++)  
{
System.out.println("Enter the customer "+(i+1)+" detail:");  
String a = br.readLine();  
csvList.add(a);  
}
List<Customer> customers = Customer.populateCustomers(csvList);  
displayCustomerDetails(customers);  
System.out.println("Enter the substring to search from customer list:");  
String a = br.readLine();  
List<Customer> customers1 = Customer.findCustomerNameFromList(customers, a);  
displayCustomerDetails(customers1);  
}
public static void displayCustomerDetails(List<Customer> customers)  
{
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");  
System.out.format("%-5s %-15s %-5s %-25s %-20s %s\n", "Id","Name","Gender","Email","Contact no","Created on");  
/
/fill code here.  
for(Customer c:customers){  
System.out.format("%-5s %-15s %-5s %-25s %-20s %s\n",  
c.getId(),c.getName(),c.getGender(),c.getEmail(),c.getContactNumber(),sdf.format(c.getCreatedOn()));  
}
}
}
Page of  
Customer & Hashmaps  
Create a class named as Customer, which contains following private variables/ attributes,  
Member Field  
Type  
name  
id  
Long  
name  
String  
gender  
email  
Character (M/F)  
String  
contactNumber  
String  
Date (time in 24 hrs clock) dd/MM/yyyy  
HH:mm:ss  
createdOn  
address  
Address  
Mark all the attributes as private  
Create / Generate appropriate Getters & Setters.  
Add a default constructor and a parameterized constructor to take in all attributes.  
No Method Name  
Method Description  
This method returns a Hashmap <String  
state, Integer count>. The key would be  
the state name and count would be the  
number of customers in the particular  
state  
public static HashMap<String, Integer>  
convertCsvToMap(List<String> csvDetails)  
1
This method returns the customer list,  
which is sorted (Ascending) based on  
both state and name. State sorted  
based on string ascending order.  
Customer sorted based on name  
ascending order.  
public static List<Customer>  
getCustomerListFromMap(Map<String,  
Integer> customerMap)  
2
Create a class named as Address, which contains following private variable/ attributes,  
Member Field name  
Type  
street  
city  
String  
String  
String  
String  
state  
country  
zipCode  
Integer  
Include appropriate getters and setters.  
Add a default constructor and a parameterized constructor to take in all attributes.  
Hint: You can get all the keys from hashmap and create a sorted list.  
State  sorted based on string ascending order.  
Customer  sorted based on name ascending order.  
Please add the address data member from the template code.  
Also for the second function, Use the arraylist as a static variable or additional attribute.  
Input Format:  
The first input consists of an integer that corresponds to the number of customers n.  
The next n input consists of a string that corresponds to the customer details, which is separated by the comma (,).  
Input sequence - id,name,email,state,country.  
Output Format:  
The first list format is,  
"
%-15s %s\n","State","No of customer(s)"  
Second list:  
The Format for the output is,  
"
"
%-5s %-15s %-5s %-20s %-20s %-15s %-15s %-15s %s\n", "Id", "Name", "Gender", "Email", "Created on", "City", "State", "Country",  
Zipcode"  
Sample Input and Output:  
Enter the number of customer:  
10  
Enter the customer 1 details:  
,John Smith,M,johnsmith@a.com,+89-7485-8578974885,15/01/2016 10:30:00,112th St,Utica,New York,USA,13455  
Enter the customer 2 details:  
,Aekerman,M,aekerman@a.com,+99-7489-8857945569,14/02/2016 16:30:00,Avenue,Austin,Texas,USA,88596  
Enter the customer 3 details:  
,Madeleine,F,madeleine@a.com,+88-7859-7748599989,25/01/2016 10:00:00,155th St,Plano,Texas,USA,56684  
Enter the customer 4 details:  
,Edrick,M,edrick@a.com,+99-7482-4115233987,18/12/2016 07:30:00,111th St,Sitka,Alaska,USA,66584  
Enter the customer 5 details:  
,Tedmond,M,tedmond@a.com,+77-8599-4225610074,05/01/2016 08:30:00,Parc St,Olympia,Washington,USA,85574  
,Nelson,M,nelson@a.com,+78-7488-4221258447,02/01/2017 10:30:00,5th St,Dayton,Ohio,USA,84587  
,Dalton,M,dalton@a.com,+78-8547-8555479512,15/01/2017 20:30:00,North St,Buffallo,New York,USA,25664  
Enter the customer 8 details:  
,Raymond,M,raymond@a.com,+89-7484-8577458895,25/02/2017 10:30:00,15th St,Waco,Texas,USA,7858  
Enter the customer 9 details:  
,Rosemary,F,rosemary@a.com,+88-4888-7485998741,20/02/2017 12:30:00,15th St,Tacoma,Washington,USA,87458  
0,Ruford,M,ruford@a.com,+84-422-9887485995,22/03/2017 9:30:00,9th St,Butte,Montana,USA,22458  
1
2
3
4
5
6
7
8
9
1
State  
No of customer(s)  
Alaska  
1
1
2
1
3
2
Montana  
New York  
Ohio  
Texas  
Washington  
Gende  
r
Created  
on  
Countr Zipcod  
Id Name  
Email  
City  
State  
y
e
1
6
8/12/201  
07:30:00  
4
Edrick  
M
Sitka  
Alaska  
USA  
66584  
1
0
22/03/201  
7 09:30:00  
Ruford  
Dalton  
M
M
M
M
M
F
Butte Montana USA  
Buffallo New York USA  
Utica New York USA  
22458  
25664  
13455  
84587  
88596  
56684  
7858  
1
7
5/01/201  
20:30:00  
7
1
6
2
3
8
9
5
John  
Smith  
15/01/201  
6 10:30:00  
0
7
2/01/201  
10:30:00  
Nelson  
Dayton Ohio  
Austin Texas  
Plano Texas  
Waco Texas  
USA  
USA  
USA  
USA  
USA  
USA  
Aekerma  
n
Madelein  
e
aekerman@a.co 14/02/201  
6 16:30:00  
madeleine@a.co 25/01/201  
6 10:00:00  
2
7
5/02/201  
10:30:00  
Raymond M  
Rosemar  
y
20/02/201 Tacom Washingto  
7 12:30:00 a  
F
87458  
85574  
n
0
6
5/01/201 Olympi Washingto  
08:30:00 a  
Tedmond M  
n
main  
import java.io.*;  
import java.text.SimpleDateFormat;  
import java.util.*;  
public class Main {  
static List<Customer> customerList;  
static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");  
static  
{
customerList = new ArrayList<>();  
try  
{
customerList.add(new Customer(1, "John Smith",'M', "johnsmith@a.com", "+98-7488-  
554744596",sdf.parse("15/02/2017 16:30:00"),  
8
9
7
7
8
8
8
8
new Address("15th St","Buffalo", "New York", "USA", 14220)));  
customerList.add(new Customer(2, "Aekerman",'M', "aekerman@a.com","+78-7485-  
555874846",sdf.parse("18/03/2017 15:45:00"),  
new Address("Avenue","Plano", "Texas", "USA", 75025)));  
customerList.add(new Customer(3, "Madeleine",'F', "madeleine@a.com", "+78-9855-  
488742136",sdf.parse("22/02/2017 16:45:00"),  
new Address("Parc St","Lubbock", "Texas", "USA", 79404)));  
customerList.add(new Customer(4, "Edrick",'M', "edrick@a.com", "+99-8787-  
844859978",sdf.parse("15/03/2017 15:45:00"),  
new Address("145th St","Wasilla", "Alaska", "USA", 99629)));  
customerList.add(new Customer(5, "Tedmond", 'M', "tedmond@a.com", "+88-7844-  
854799658",sdf.parse("15/03/2017 15:45:00"),  
new Address("Port Townsend","Tacoma", "Washington", "USA", 98412)));  
customerList.add(new Customer(6, "Nelson",'M', "nelson@a.com", "+88-7848-  
857488956",sdf.parse("17/05/2017 10:35:00"),  
new Address("1st St","Akron", "Ohio", "USA", 44304)));  
customerList.add(new Customer(7, "Dalton", 'M', "dalton@a.com", "+88-8879-  
854741124",sdf.parse("01/05/2017 17:25:00"),  
new Address("Lake city", "Newburgh", "New York", "USA", 12550)));  
customerList.add(new Customer(8, "Raymond", 'M', "raymond@a.com", "+89-7748-  
859112478",sdf.parse("17/06/2017 08:45:00"),  
new Address("Wall Street","Texas City", "Texas", "USA", 77591)));  
customerList.add(new Customer(9, "Rosemary", 'F', "rosemary@a.com", "+89-7844-8857489958",  
sdf.parse("22/04/2017 16:15:00"),  
new Address("Georgetown","Olympia", "Washington", "USA", 98506)));  
customerList.add(new Customer(10, "Ruford", 'M', "ruford@a.com", "+88-7485-8597448596",  
sdf.parse("12/02/2017 09:05:00"),  
new Address("Baker street", "Miles City", "Montana", "USA", 59301)));  
}
catch(Exception e)  
{
e.printStackTrace();  
}
}
public static void main(String[] args) throws Exception {  
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));  
System.out.println("Menu\n1. Find customer by id\n2. Find customer by states\nEnter the choice:");  
switch(new Integer(bufferedReader.readLine()))  
{
case 1:  
System.out.println("Enter the Id to find customer:");  
Customer c=new Customer().findCustomerById(customerList, new Integer(bufferedReader.readLine()));  
if(c!=null)  
{
System.out.println("Customer Name: "+c.getName());  
System.out.println("Gender: "+c.getGender());  
System.out.println("Email: "+c.getEmail());  
System.out.println("Contact Number: "+c.getContactNumber());  
System.out.println("Street: "+c.getAddress().getStreet());  
System.out.println("City: "+c.getAddress().getCity());  
System.out.println("State: "+c.getAddress().getState());  
System.out.println("Country: "+c.getAddress().getCountry());  
System.out.println("Zip code: "+c.getAddress().getZipCode());  
}
else  
System.out.println("No Customer with that id");  
break;  
case 2:  
System.out.println("Enter the state:");  
List<Customer> clist=new Customer().findCustomerListByState(customerList, bufferedReader.readLine());  
if(!(clist.isEmpty()))  
{
System.out.format("%-15s %-20s %-20s %-15s %-15s %-15s %s\n","Name","Email", "Contact  
no","Street","City","Country","Zipcode");  
for(Customer c1:clist){  
System.out.format("%-15s %-20s %-20s %-15s %-15s %-15s %d\n",c1.getName(),c1.getEmail(),  
c1.getContactNumber(),c1.getAddress().getStreet(),c1.getAddress().getCity(),c1.getAddress().getCountry(),c1.getAd  
dress().getZipCode());  
}
}
else  
System.out.println("No customer belongs that state");  
break;  
}
}
}
customer  
import java.util.ArrayList;  
import java.util.Date;  
import java.util.List;  
public class Customer {  
private int id;  
private String name;  
private Character gender;  
private String email;  
private String contactNumber;  
private Date createdOn;  
private Address address;  
public Address getAddress() {  
return address;  
}
public void setAddress(Address address) {  
this.address = address;  
}
public Customer(int id, String name, Character gender, String email,  
String contactNumber, Date createdOn, Address address) {  
super();  
this.name = name;  
this.gender = gender;  
this.email = email;  
this.contactNumber = contactNumber;  
this.createdOn = createdOn;  
this.address = address;  
}
@Override  
public String toString() {  
return "Customer: "+name+"\nCustomer contact details:"+contactNumber+", "+email;  
}
public Customer() {  
super();  
/
}
/ TODO Auto-generated constructor stub  
public int getId() {  
return id;  
}
public void setId(int id) {  
}
public String getName() {  
return name;  
}
public void setName(String name) {  
this.name = name;  
}
public Character getGender() {  
return gender;  
}
public void setGender(Character gender) {  
this.gender = gender;  
}
public String getEmail() {  
return email;  
}
public void setEmail(String email) {  
this.email = email;  
}
public String getContactNumber() {  
return contactNumber;  
}
public void setContactNumber(String contactNumber) {  
this.contactNumber = contactNumber;  
}
public Date getCreatedOn() {  
return createdOn;  
}
public void setCreatedOn(Date createdOn) {  
this.createdOn = createdOn;  
}
public static Customer findCustomerById(List<Customer> customerList, int id){  
Customer c=null;  
for(Customer c1:customerList){  
if(c1.getId()==id)  
c=c1;  
}
return c;  
}
public static List<Customer> findCustomerListByState(List<Customer> customerList, String state){  
List<Customer> clist=new ArrayList<Customer>();  
for(Customer c:customerList){  
if(c.getAddress().getState().equalsIgnoreCase(state))  
clist.add(c);  
}
return clist;  
}
}
address  
public class Address {  
private String street,city,state,country;  
private int zipCode;  
public String getStreet() {  
return street;  
}
public void setStreet(String street) {  
this.street = street;  
}
public String getCity() {  
return city;  
}
public void setCity(String city) {  
this.city = city;  
}
public String getState() {  
return state;  
}
public void setState(String state) {  
this.state = state;  
}
public String getCountry() {  
return country;  
}
public void setCountry(String country) {  
this.country = country;  
}
public int getZipCode() {  
return zipCode;  
}
public void setZipCode(int zipCode) {  
this.zipCode = zipCode;  
}
public Address(String street, String city, String state, String country,  
int zipCode) {  
super();  
this.street = street;  
this.city = city;  
this.state = state;  
this.country = country;  
this.zipCode = zipCode;  
}
public Address() {  
super();  
/
}
/ TODO Auto-generated constructor stub  
}
Page of  
Car-Service Management System - Requirement 1  
Your friend, a mechanical engineer is very passionate about cars  
and wants to be an entrepreneur. He decides to start his own car  
service center and with his knowledge about cars has the  
capability to service all different brands of cars. You are also very  
keen to help him out in any means possible.  
One fine day, your friend approaches you to help him setup and  
automate the process of tracking various customers and their  
service feedbacks. You decide to quickly build a small system to  
solve the problem.  
Based on the class diagram given below, you start to build a  
prototype of the application.  
Requirement 1:  
td p { margin-bottom: 0cm; direction: ltr; color: rgb(0, 0, 10); text-  
align: left; }td p.western { font-family: "Liberation Serif",serif; font-  
size: 12pt; }td p.cjk { font-family: "Droid Sans Fallback"; font-size:  
12pt; }td p.ctl { font-family: "FreeSans"; font-size: 12pt; }p {  
margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 10); line-  
height: 120%; text-align: left; }p.western { font-family: "Liberation  
Serif",serif; font-size: 12pt; }p.cjk { font-family: "Droid Sans  
Fallback"; font-size: 12pt; }p.ctl { font-family: "FreeSans"; font-  
size: 12pt; }a:link { }  
Let’s start off by creating a customer class based on the below  
mentioned specifications.  
a. Create a Customer Class with the following attributes:  
Member Field Name  
customerId  
firstName  
lastName  
gender  
email  
Type  
Long  
String  
String  
String  
String  
String  
String  
phoneNumber  
address  
b. Mark all the attributes as private  
c. Create / Generate appropriate Getters & Setters  
d. Add a default constructor and a parameterized constructor to  
take in all attributes in the given order: Customer(Long  
customerId, String firstName, String lastName, String gender,  
String email, String phoneNumber, String address)  
e.  
When the “customer” object is printed, it should  
display the following details: [Override the toString method]  
Print format:  
Customer:firstname,lastname  
Contact details:phoneNumber,email,address  
f.Two customers are considered same if they have the same name  
(both firstname and lastname), email and phone number.  
Implement the logic in the appropriate function. (Case –  
Insensitive) [Override the equals method]  
The Input to your program would be details of two customers, you  
need to display their details as given in "requirement e" and compare  
the two customers and display if the customers are same or unique.  
Sample INPUT & OUTPUT 1:  
Customer1 :  
customer id:  
1
first name:  
Arun  
last name:  
Kumar  
gender:  
Male  
phone number:  
9897969594  
address:  
Coimbatore North  
Customer2 :  
customer id:  
123  
first name:  
Arun  
last name:  
Kumar  
gender:  
Male  
phone number:  
9897969594  
address:  
Coimbatore North  
Customer 1  
Customer:Arun,Kumar  
Contact details:9897969594,arun123@gmail.com,Coimbatore  
North  
Customer 2  
Customer:Arun,Kumar  
Contact details:9897969594,arun123@gmail.com,Coimbatore  
North  
Customer 1 is same as Customer 2  
Sample Input and Output 2:  
Customer1 :  
customer id:  
1
first name:  
Vijay  
last name:  
Kumar  
gender:  
Male  
phone number:  
876541234  
9
address:  
North Chennai  
Customer2 :  
customer id:  
23  
first name:  
Karmega  
last name:  
Kulazhi  
gender:  
Female  
phone number:  
7785674563  
address:  
Kurangani, Theni, Tamilnadu  
Customer 1  
Customer:Vijay,Kumar  
Contact details:9876541234,Vijayajit@gmail.com,North Chennai  
Customer 2  
Customer:Karmega,Kulazhi  
Contact details:7785674563,Karmegam@gmail.com,Kurangani, Theni, Tamilnadu  
Customer 1 and Customer 2 are different  
public class Customer {  
private Long customerId;  
private String firstName, lastName, gender, email,  
phoneNumber, address;  
public Long getCustomerId() {  
return customerId;  
}
public void setCustomerId(Long customerId) {  
this.customerId = customerId;  
}
public String getFirstName() {  
return firstName;  
}
public void setFirstName(String firstName) {  
this.firstName = firstName;  
}
public String getLastName() {  
return lastName;  
}
public void setLastName(String lastName) {  
this.lastName = lastName;  
}
public String getGender() {  
return gender;  
}
public void setGender(String gender) {  
this.gender = gender;  
}
public String getEmail() {  
return email;  
}
public void setEmail(String email) {  
this.email = email;  
}
public String getPhoneNumber() {  
return phoneNumber;  
}
public void setPhoneNumber(String phoneNumber) {  
this.phoneNumber = phoneNumber;  
}
public String getAddress() {  
return address;  
}
public void setAddress(String address) {  
this.address = address;  
}
public Customer(Long customerId, String firstName, String  
lastName,  
String gender, String email, String phoneNumber, String  
address) {  
super();  
this.customerId = customerId;  
this.firstName = firstName;  
this.lastName = lastName;  
this.gender = gender;  
this.email = email;  
this.phoneNumber = phoneNumber;  
this.address = address;  
}
public Customer() {  
super();  
}
@Override  
public int hashCode() {  
final int prime = 31;  
int result = 1;  
result = prime * result + ((email == null) ? 0 :  
email.hashCode());  
result = prime * result  
+
((firstName == null) ? 0 : firstName.hashCode());  
result = prime * result  
((lastName == null) ? 0 : lastName.hashCode());  
result = prime * result  
((phoneNumber == null) ? 0 :  
+
+
phoneNumber.hashCode());  
return result;  
}
@Override  
public boolean equals(Object obj) {  
if (this == obj)  
return true;  
if (obj == null)  
return false;  
if (getClass() != obj.getClass())  
return false;  
Customer other = (Customer) obj;  
if (email == null) {  
if (other.email != null)  
return false;  
}
else if (!email.equals(other.email))  
return false;  
if (firstName == null) {  
if (other.firstName != null)  
return false;  
}
else if (!firstName.equals(other.firstName))  
return false;  
if (lastName == null) {  
if (other.lastName != null)  
return false;  
}
else if (!lastName.equals(other.lastName))  
return false;  
if (phoneNumber == null) {  
if (other.phoneNumber != null)  
return false;  
}
else if (!phoneNumber.equals(other.phoneNumber))  
return false;  
return true;  
}
@Override  
public String toString() {  
return "Customer:"+ firstName +","+ lastName +  
\nContact details:"+  
"
phoneNumber+","+email+","+address;  
}
/
/fill the code  
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
public class Main {  
public static void main(String[] args) throws IOException  
{
Long customerId;  
String firstName, lastName, gender, email,  
phoneNumber, address, otherCustomerDetails;  
BufferedReader br = new BufferedReader(new  
InputStreamReader(System.in));  
Customer customer[] = new Customer[2];  
int i,ind=1;  
for (i = 0; i <2; i++) {  
System.out.println("Customer" + (i+1) + " :");  
System.out.println("customer id: ");  
customerId = Long.parseLong(br.readLine());  
System.out.println("first name: ");  
firstName = br.readLine();  
System.out.println("last name: ");  
lastName = br.readLine();  
System.out.println("gender: ");  
gender = br.readLine();  
System.out.println("email: ");  
email = br.readLine();  
System.out.println("phone number: ");  
phoneNumber = br.readLine();  
System.out.println("address: ");  
address = br.readLine();  
customer[i]=new Customer(customerId, firstName,  
lastName,  
gender, email, phoneNumber, address);  
/fill the code  
/
}
for(Customer c:customer)  
{
System.out.println("Customer "+ind);  
System.out.println(c);  
ind++;  
}
if(customer[0].equals(customer[1]))  
System.out.println("Customer 1 is same as Customer 2");  
else  
System.out.println("Customer 1 and Customer 2 are  
different");  
}
}
Page of  
Car-Service Management System - Requirement 2  
Requirement 2:  
a.Create a Car Class with the following attributes:  
Member Field Name  
licenceNumber  
model  
Type  
String  
String  
Double  
Integer  
currentMileage  
engineSize  
b.Mark all the attributes as private & Create appropriate  
Getters & Setters  
c.Add a default constructor and a parameterized constructor  
to take in all attributes in the given order  
Car(String licenceNumber,String model,Double currentMileage,Integer engineSize)  
d. Add a static method findCar in Car class which takes licenceNumber as input and  
returns the Car if the car object is found or null if the car object is not found.  
e. Add a static findCarList method in Car class which will take a model(car  
model) and carList(list of cars) as parameters and return a List of cars for the  
given model from the list or null if no cars found. For these conditions,  
please refer the content to be printed in Sample IO.  
Override the toString method to print the car details :  
Print format:  
Licence Number:licenceNumber  
Model:model  
Sample Input & Output:  
Menu:  
1
2
3
4
1
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
Licence Number:  
MH1420110062821  
Model:  
Verna  
Current Mileage:  
2
4.35  
Engine Size:  
461  
Menu:  
1
1
2
3
4
1
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
Licence Number:  
MH1420110062823  
Model:  
Swift  
Current Mileage:  
1
7.35  
Engine Size:  
231  
Menu:  
1
1
2
3
4
1
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
Licence Number:  
MH1420110045821  
Model:  
Verna  
Current Mileage:  
1
4.35  
Engine Size:  
231  
Menu:  
1
1
2
3
4
2
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
Licence Number  
MH1420110062821  
Licence Number:MH1420110062821  
Model:Verna  
Menu:  
1
2
3
4
3
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
Model  
Verna  
Licence Number:MH1420110062821  
Model:Verna  
Licence Number:MH1420110045821  
Model:Verna  
Menu:  
1
2
3
4
2
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
Licence Number  
MH1420110062823  
Licence Number:MH1420110062823  
Model:Swift  
Menu:  
1
2
3
4
3
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
Model  
Figo  
Car Figo not found  
Menu:  
1
2
) Add a Car  
) Find a Car  
3
4
4
) Find CarList  
) Exit  
Sample Input and output 2:  
Menu:  
1
2
3
4
1
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
Licence Number:  
TN1220151247856  
Model:  
Verna  
Current Mileage:  
2
2
Engine Size:  
230  
Menu:  
1
1
2
3
4
2
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
Licence Number  
TN1220151247415  
Licence Number not present  
Menu:  
1
2
3
4
4
) Add a Car  
) Find a Car  
) Find CarList  
) Exit  
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.util.ArrayList;  
public class Main {  
public static void main(String[] args) throws IOException {  
ArrayList<Car> carList = new ArrayList<Car>();  
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
while(true)  
{
String menu = "Menu: \n1) Add a Car\n" +"2) Find a Car\n" +"3) Find CarList\n" +"4) Exit";  
System.out.println(menu);  
/
/fill the code  
int option=Integer.parseInt(br.readLine());  
if(option == 1) {  
/
/fill the code  
carList.add(Car.addCar(br));  
}
if(option == 2) {  
System.out.println("Licence Number");  
String licNo=br.readLine();  
if(Car.findCar(licNo, carList)!=null)  
System.out.println(Car.findCar(licNo, carList));  
else  
System.out.println("Licence Number not present");  
/
/fill the code  
}
if(option == 3) {  
ArrayList<Car> carList1 = new ArrayList<Car>();  
System.out.println("Model");  
String model=br.readLine();  
carList1=Car.findCarList(model, carList);  
if(carList1!=null)  
{
for(Car c:carList1)  
{
System.out.println(c);  
}
}
else  
System.out.println("Car "+model+" not found");  
}
if(option == 4) {  
/
/fill the code  
System.exit(0);  
}
}
}
}
import java.io.BufferedReader;  
import java.util.*;  
public class Car {  
/
/fill the code  
private String licenceNumber,model;  
private Double currentMileage;  
private Integer engineSize;  
public String getLicenceNumber() {  
return licenceNumber;  
}
public void setLicenceNumber(String licenceNumber) {  
this.licenceNumber = licenceNumber;  
}
public String getModel() {  
return model;  
}
public void setModel(String model) {  
this.model = model;  
}
public Double getCurrentMileage() {  
return currentMileage;  
}
public void setCurrentMileage(Double currentMileage) {  
this.currentMileage = currentMileage;  
}
public Integer getEngineSize() {  
return engineSize;  
}
public void setEngineSize(Integer engineSize) {  
this.engineSize = engineSize;  
}
public Car(String licenceNumber, String model, Double currentMileage,  
Integer engineSize) {  
super();  
this.licenceNumber = licenceNumber;  
this.model = model;  
this.currentMileage = currentMileage;  
this.engineSize = engineSize;  
}
public Car() {  
super();  
}
/
/Dont change the specification of this method  
public static Car addCar(BufferedReader br) {  
String licenceNumber, model;Double currentMileage;Integer engineSize;  
Car c = null;  
try {  
System.out.println("Licence Number: ");  
licenceNumber = br.readLine();  
System.out.println("Model: ");  
model = br.readLine();  
System.out.println("Current Mileage: ");  
currentMileage = Double.parseDouble(br.readLine());  
System.out.println("Engine Size: ");  
engineSize = Integer.parseInt(br.readLine());  
c = new Car(licenceNumber,model,currentMileage,engineSize);  
return c;  
}
catch(Exception e) {  
System.out.println("Could not create Car");  
}
return c;  
}
public static Car findCar(String licNo, ArrayList<Car> carList) {  
/fill the code  
/
for(Car c:carList)  
{
if(c.getLicenceNumber().equals(licNo))  
{
return c;  
}
}
return null;  
}
@
Override  
public String toString() {  
return "Licence Number:" + licenceNumber + "\nModel:" + model;  
}
public static ArrayList<Car> findCarList(String model, ArrayList<Car> carList) {  
ArrayList<Car> cL=new ArrayList<>();  
int f=0;  
for(Car c:carList)  
{
if(c.getModel().equals(model))  
{
cL.add(c);  
f=1;  
}
}
if(f==1)  
return cL;  
else  
return null;  
/
/fill the code  
}
}
Page of  
Car-Service Management System - Requirement 3  
There are always typical human entry errors that need to be validated so that the data being saved in the  
system is valid and can be used for later processing. Lets define some simple rules so that data being  
collected are valid.  
Create a class named as Main, which contains following static methods.  
a) Create a method validateLicenceNumber(String licenceNumber) which takes a license  
number(String) and returns boolean (true or false),based on the below rules.  
A licence Number is valid if all the below rules are true.  
2
2
4
7
chars-state name. ( 2 characters A to Z)  
numbers-branch code (integers) - valid range between 10 - 50  
numbers-licence issued year - valid range between - (2005 to 2016) inclusive of both years.  
numbers -profile id (Any digit should not contain 0).  
eg:MH1420116662821 is a valid licence number.  
b) Write a method isExperiencedDriver(String licenceNumber) which takes a license number(String)  
and returns a boolean.  
This function checks for experience of a driver with respect to licence Number. The year of the  
licence issue starts from 5 th chacter (yyyy determines the year).  
If year of license issued is equal to or greater than 5 years from current year then return true  
,
else return false. Assume today’s date as 28-11-2017. If the method returns true, then the  
driver is termed as experienced. If its less than 5 years, then print as Not Experienced Driver.  
Menu:  
1
) Validate licence Number  
2) Check Driver Experience  
Sample Input and Output 1:  
Enter license number:  
MH1420110062821  
Menu:  
1
) Validate licence Number  
2
) Check Driver Experience  
Enter choice:  
1
License number is not valid  
Sample Input and Output 2:  
Enter license number:  
tn482018547585  
Menu:  
1
2
) Validate licence Number  
) Check Driver Experience  
Enter choice:  
1
License number is not valid  
Sample Input and Output 3:  
Enter license number:  
TN5920151122556  
Menu:  
1
2
) Validate licence Number  
) Check Driver Experience  
Enter choice:  
1
License number is not valid  
Sample Input and Output 4:  
Enter license number:  
KL2620044451236  
Menu:  
1
2
) Validate licence Number  
) Check Driver Experience  
Enter choice:  
1
License number is not valid  
Sample Input and Output 5:  
Enter license number:  
TN4520124482563  
Menu:  
1
2
) Validate licence Number  
) Check Driver Experience  
Enter choice:  
1
License number is valid  
Sample Input and Output 6:  
Enter license number:  
KA1220112235647  
Menu:  
1
) Validate licence Number  
2
) Check Driver Experience  
Enter choice:  
2
Experienced Driver  
Sample Input and Output 7:  
Enter license number:  
TN5420154485263  
Menu:  
1
) Validate licence Number  
2
) Check Driver Experience  
Enter choice:  
2
Not Experienced Driver  
td p { margin-bottom: 0cm; direction: ltr; color: rgb(0, 0, 10); text-align: left; }td p.western { font-  
family: "Liberation Serif",serif; font-size: 12pt; }td p.cjk { font-family: "Droid Sans Fallback"; font-  
size: 12pt; }td p.ctl { font-family: "FreeSans"; font-size: 12pt; }p { margin-bottom: 0.25cm;  
direction: ltr; color: rgb(0, 0, 10); line-height: 120%; text-align: left; }p.western { font-family:  
"Liberation Serif",serif; font-size: 12pt; }p.cjk { font-family: "Droid Sans Fallback"; font-size: 12pt;  
}p.ctl { font-family: "FreeSans"; font-size: 12pt; }a:link { }  
import java.io.BufferedReader;  
import java.io.InputStreamReader;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Calendar;  
import java.util.Date;  
public class Main {  
public static void main(String[] args) throws Exception {  
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
System.out.println("Enter license number:");  
String licenseNumber = br.readLine();  
System.out.println("Menu:\n" +  
"1) Validate licence Number\n" +  
"2) Check Driver Experience");  
System.out.println("Enter choice: ");  
Integer choice = Integer.parseInt(br.readLine());  
switch(choice) {  
case 1:  
if(validateLicenseNumber(licenseNumber)){  
System.out.println("License number is valid");  
}
else {  
System.out.println("License number is not valid");  
}
break;  
case 2:  
if(isExperiencedDriver(licenseNumber)) {  
System.out.println("Experienced Driver");  
}
else {  
System.out.println("Not Experienced Driver");  
}
break;  
default:  
System.out.println("Invalid option");  
}
}
public static Boolean validateLicenseNumber(String licenceNumber) throws ParseException {  
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");  
Date currentDate = sdf.parse("28-11-2017");  
//fill code here  
if(Character.isUpperCase(licenceNumber.charAt(0))&&Character.isUpperCase(licenceNumber.  
charAt(1)))  
{
try{  
int state=Integer.parseInt(licenceNumber.substring(2,4));  
if(state<=50&&state>=10)  
{
int year=Integer.parseInt(licenceNumber.substring(4,8));  
if(year>=2005&&year<=2016)  
{
String id=licenceNumber.substring(8,licenceNumber.length());  
for(int i=0;i<id.length();i++)  
{
if(id.charAt(i)=='0')  
{
return false;  
}
}
return true;  
}
}
}
catch(Exception e)  
{
return false;  
}
}
return false;  
}
public static Boolean isExperiencedDriver(String licenceNumber) throws ParseException {  
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");  
Date currentDate = sdf.parse("28-11-2017");  
//fill code here  
int year=Integer.parseInt(licenceNumber.substring(4,8));  
return year<2013;  
}
}
Page of  
Car-Service Management System - Requirement 5  
Requirement 5:  
a) Create a Customer Class with the following attributes:  
Member Field Name  
customerId  
firstName  
lastName  
Type  
Long  
String  
String  
String  
String  
String  
String  
gender  
email  
phoneNumber  
address  
b) Mark all the attributes as private  
c) Create / Generate appropriate Getters & Setters  
d) Add a default constructor and a parameterized constructor to take in all attributes in the given order: Customer(Long customerId, String firstName, String  
lastName, String gender, String email, String phoneNumber, String address)  
e) A valid email has an @ and ends with “.com / .org”.  
Create a method validateEmail in customer class with return type as void and check for valid email . During the parse, if an email id is invalid, Raise the custom  
exception(InvalidEmailException) and dont add the customer into the list. Print messege "Invalid Email for the user" for the exception.  
f) Write a Comparator class named CustomerComparator implementing Comparator Interface. This comparator should sort the customers based on firstname.  
After reading all the inputs, Apply the comparator on the inputlist read and display the result.  
The output format should be System.out.format("%-5s %-15s %-15s %-15s %-15s %s\n","Id","First Name","Last Name","Gender","Email","Phone");  
Sample Input and Output:  
Enter customer details:  
1
,Vel,Murugan,Male,vel@mail.com,9876543210,Coimbatore  
Do you want to continue?  
yes  
Enter customer details:  
2
,Mani,Gandan,male,mani@mail.org,9873216540,CBE  
Do you want to continue?  
yes  
Enter customer details:  
3
,Thana,Rathanam,male,thana@mail.in,9783210456,Karur  
InvalidEmailException: Invalid Email for the user  
Do you want to continue?  
yes  
Enter customer details:  
4
,Karthi,Keyan,male,keyan@mail.edu,9632587410,Tirupur  
InvalidEmailException: Invalid Email for the user  
Do you want to continue?  
yes  
Enter customer details:  
5
,Soori,yaa,male,yaa@yaa.co.in,9875321460,Chennnai  
InvalidEmailException: Invalid Email for the user  
Do you want to continue?  
no  
Id First Name  
Last Name  
Gandan  
Gender  
male  
Male  
mani@mail.org 9873216540  
vel@mail.com 9876543210  
Phone  
2
1
Mani  
Vel  
Murugan  
import java.util.Comparator;  
public class CustomerComparator implements Comparator<Customer>{  
Override  
@
public int compare(Customer c1, Customer c2) {  
return c1.getFirstName().compareTo(c2.getFirstName());  
}
}
public class Customer {  
public long getCustomerId() {  
return customerId;  
}
public void setCustomerId(long customerId) {  
this.customerId = customerId;  
}
public String getFirstName() {  
return firstName;  
}
public void setFirstName(String firstName) {  
this.firstName = firstName;  
}
public String getLastName() {  
return lastName;  
}
public void setLastName(String lastName) {  
this.lastName = lastName;  
}
public String getGender() {  
return gender;  
}
public void setGender(String gender) {  
this.gender = gender;  
}
public String getEmail() {  
return email;  
}
public void setEmail(String email) {  
this.email = email;  
}
public String getPhoneNumber() {  
return phoneNumber;  
}
public void setPhoneNumber(String phoneNumber) {  
this.phoneNumber = phoneNumber;  
}
public String getAddress() {  
return address;  
}
public void setAddress(String address) {  
this.address = address;  
}
public Customer(long customerId, String firstName, String lastName,  
String gender, String email, String phoneNumber, String address) {  
super();  
this.customerId = customerId;  
this.firstName = firstName;  
this.lastName = lastName;  
this.gender = gender;  
this.email = email;  
this.phoneNumber = phoneNumber;  
this.address = address;  
}
public Customer()  
{
}
private long customerId;  
private String firstName;  
private String lastName;  
private String gender;  
private String email;  
private String phoneNumber;  
private String address;  
public void validateEmail() throws InvalidEmailException  
{
String input=this.getEmail();  
if(!(input.endsWith(".com")||input.endsWith(".org"))&&(input.contains("@")))  
{
throw new InvalidEmailException("Invalid Email for the user");  
}
else  
{
}
}
}
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.util.ArrayList;  
import java.util.Collections;  
import java.util.List;  
public class Main {  
public static void main(String[] args) throws IOException {  
List<Customer> customerList = new ArrayList<>();  
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
String customerDetails;  
String choice;  
do {  
System.out.println("Enter customer details:");  
customerDetails=br.readLine();  
String input[]=customerDetails.split(",");  
Customer c = new Customer(Long.parseLong(input[0]),input[1],input[2],input[3],input[4],input[5],input[6]);  
try  
{
c.validateEmail();  
customerList.add(c);  
}
catch (InvalidEmailException e) {  
System.out.println(e);  
}
System.out.println("Do you want to continue?");  
choice = br.readLine();  
}
while(choice.equals("yes"));  
Collections.sort(customerList, new CustomerComparator());  
System.out.format("%-5s %-15s %-15s %-15s %-15s %s\n","Id","First Name","Last Name","Gender","Email","Phone");  
for(Customer customer : customerList) {  
System.out.format("%-5s %-15s %-15s %-15s %-15s  
%
s\n",customer.getCustomerId(),customer.getFirstName(),customer.getLastName(),customer.getGender(),customer.getEmail(),customer.getPhoneNu  
mber());  
}
}
}
public class InvalidEmailException extends Exception{  
public InvalidEmailException(String msg)  
{
super(msg);  
}
}